Action Does Not Perform

Asked

Viewed 73 times

1

I am using STS authentication, and given certain configuration in web.config I can’t get my (Sign In) action to perform what it should.

to elute follows code:

[AllowAnonymous]
    public class SegurancaController : SecurityController
    {
        public ActionResult Index()
        {
....
        }

        [ValidateInput(false)]
        [HttpPost]
        [ActionName("Index")]
        public ActionResult IndexPost()
        {
....
        }
    }

Securitycontroller:

[AllowAnonymous]
        public ActionResult SignIn(string issuer)
        {
            var wSFederationAuthenticationModule = FederatedAuthentication.WSFederationAuthenticationModule;
            string str = null;
            if (!base.User.Identity.IsAuthenticated)
            {
                str =
                    new SignInRequestMessage(new Uri(string.IsNullOrEmpty(issuer) ? wSFederationAuthenticationModule.Issuer : issuer),
                        wSFederationAuthenticationModule.Realm, wSFederationAuthenticationModule.Reply).WriteQueryString();
            }
            return new RedirectResult(str ?? wSFederationAuthenticationModule.Reply);
        }

And Web.config

<authentication mode="Forms">
      <forms loginUrl="~/Seguranca" name=".ASPXFORMSAUTH" timeout="2880"  defaultUrl="~/home" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>

NOTE: If tags <authorization><deny users="?" /></authorization> are commented I can run the Normalmante URL... but I miss the check if the user is logged in.

  • 1

    What I get FUDID* is that the guys instead of participating, go around giving downvote...

  • 1

    And it’s not just you.

1 answer

1


Since I couldn’t solve it, I solved the case in another way.

I added a Handler to intercept requests as follows.

public class CustomActionFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            var isAuthenticate = filterContext.HttpContext.User.Identity.IsAuthenticated;
            if (!isAuthenticate && controller != "Seguranca")
                filterContext.Result = new RedirectToRouteResult(
                    new RouteValueDictionary 
                    { 
                        { "controller", "Seguranca" }, 
                        { "action", "Index" } 
                    });
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.