0
有没有一种方法可以在每个控制器的基础上覆盖默认的400重定向(在web.config中设置)?基于MVC控制器的自定义400重定向
说我有一个管理控制器和一个帐户控制器,每个都有一个自定义的AuthorizeAttribute。有两种不同的登录表单,当AdminAuthorize属性为false时,我需要管理员控制器重定向到它。
有没有一种方法可以在每个控制器的基础上覆盖默认的400重定向(在web.config中设置)?基于MVC控制器的自定义400重定向
说我有一个管理控制器和一个帐户控制器,每个都有一个自定义的AuthorizeAttribute。有两种不同的登录表单,当AdminAuthorize属性为false时,我需要管理员控制器重定向到它。
你总是可以实现自己的authorization attribute:
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
var actionName = filterContext.ActionDescriptor.ActionName;
// TODO: Now that you know the controller name and the action name
// act accordingly or call the base method
}
}