2010-06-21 3 views
0

컨트롤러 단위로 기본 400 리디렉션 (web.config에서 설정)을 무시할 수 있습니까?MVC 컨트롤러를 기반으로하는 사용자 지정 400 리디렉션

내가 관리 컨트롤러와 계정 컨트롤러가 있다고 가정 해보십시오. 각 컨트롤러에는 사용자 지정 AuthorizeAttribute가 있습니다. 두 가지 다른 로그인 양식이 있는데 AdminAuthorize 속성이 false 인 경우 리디렉션하도록 admin 컨트롤러가 필요합니다.

답변

1

당신은 항상 구현할 수있는 자신의 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 
    } 
} 
관련 문제