2010-06-21 2 views
0

Existe-t-il un moyen de remplacer la redirection 400 par défaut (définie dans web.config) par contrôleur? Dites que j'ai un contrôleur Admin et un contrôleur de compte, chacun a un AuthorizeAttribute personnalisé. Il y a deux formulaires de connexion différents, et j'ai besoin que le contrôleur d'administration redirige vers quand l'attribut AdminAuthorize est faux.Redirection personnalisée 400 basée sur le contrôleur MVC

Répondre

1

Vous pouvez toujours mettre en œuvre votre propre 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 
    } 
} 
Questions connexes