Custom AuthorizeAttribute with custom authentication

后端 未结 3 1267
生来不讨喜
生来不讨喜 2020-12-31 13:34

I am using ASP.NET MVC 4 Web application as a front-end for some WCF services. All the user log in/log out and session control is done on the back-end. MVC app should only

3条回答
  •  我在风中等你
    2020-12-31 14:06

    Not totally sure I get it but if you create an Custom Authorization Filter that inherits from System.Web.MVC.Authorize attribute like this.

        public class CustomAuthorize : AuthorizeAttribute
        {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (CookieIsValid(filterContext.Request.Cookies["cookieyouwant"])
            {
                 filterContext.Result = new RedirectResult("DestUrl");
            }
            else
            {
                filterContext.Result = new RedirectResult("/Home/Index/NeedsLogin");
            }
        }
    }
    

    And then decorate your Methods that need to employ this Authorization will that do the trick?

提交回复
热议问题