您的位置:首页 > 编程语言 > ASP

asp.net mvc中权限判断失败时跳转页 ReturnUrl

2014-04-24 10:49 453 查看
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class AdminAuthorizeAttribute : FilterAttribute, IAuthorizationFilter
{
private readonly bool _isLogin;
public AdminAuthorizeAttribute(bool  isLogin)
{
_isLogin = isLogin;
}

public void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext == null)
throw new ArgumentNullException("filterContext");

if (OutputCacheAttribute.IsChildActionCacheActive(filterContext))
throw new InvalidOperationException(
"You cannot use [MemberAuthorize] attribute when a child action cache is active");

if (_isLogin)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
}

红色地方标注的就是返回结果

该结果会在web.config中进行配置 都会加上ReturnUrl

<authentication mode="Forms">
<forms loginUrl="~/Test/Login" timeout="2880" />
</authentication>


配置后返回结果:/Test/Login?ReturnUrl=%2fTest%2fTestKindEditor
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: