[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