您的位置:首页 > 其它

mvc登录授权特性

2016-01-14 11:53 423 查看
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
{}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: