标签:
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 {}
标签:
原文地址:http://www.cnblogs.com/Jerrycjc/p/5129703.html