当前位置: 代码迷 >> VC/MFC >> mvc登录受权特性
  详细解决方案

mvc登录受权特性

热度:184   发布时间:2016-05-02 03:19:33.0
mvc登录授权特性
    public class CommonAuthorize : AuthorizeAttribute    {        protected override bool AuthorizeCore(HttpContextBase httpContext)        {            return UserHelper.CurrentUser != null;        }        public override void OnAuthorization(AuthorizationContext filterContext)        {            if (!filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) && !filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))            {                if (UserHelper.CurrentUser == null)                {                    filterContext.Result = new RedirectResult(string.Format("/OAuth2/IndexUserInfo?returnUrl={0}", filterContext.HttpContext.Request.RawUrl));                }            }        }    }

 使用

[CommonAuthorize]    public class BaseController : Controller    {}

 

  相关解决方案