如何覆盖登录Url?
你能把它作为属性添加到AuthenticateAttribute中吗?
发布于 2012-07-03 06:04:14
在System.Web.Security.FormsAuthentication名称空间中:
FormsAuthentication.LoginUrl如果您想覆盖authorize值,只需实现您自己的Web.config属性:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class CustomAuthorize: AuthorizeAttribute{
public override void OnAuthorization(AuthorizationContext filterContext) {
//If the request does not provide authentication, then perform a redirect
if (!filterContext.HttpContext.Request.IsAuthenticated) {
var loginUrl = FormsAuthentication.LoginUrl; //Change your URL here if needed.
filterContext.Result = new RedirectResult(loginUrl);
} else {
//Since the request was authenticated, perform the default authorization check.
base.OnAuthorization(filterContext);
}
}
}https://stackoverflow.com/questions/11301790
复制相似问题