2017-05-15 10 views
0

안녕하세요 내 C# 컨트롤러에 대한 사용자 지정 필터 특성이 있습니다.MVC 필터 속성 - 필터 매개 변수로 여러 옵션

[SessionExpireFilterAttribute(UserType = UserTypes.Admin)] 

내 필터는 다음과 같이 시작합니다

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] 
    public class SessionExpireFilterAttribute : ActionFilterAttribute 
    { 
     public App.Model.UserTypes UserType { get; set; } 

     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      HttpContext ctx = HttpContext.Current; 

는 내가하고 싶은 것은 지금이 컨트롤러에 대한 권한을 하나에 연결되지 않은 여러 UserTypes을 보낼 수있을 것입니다. 사용자 유형이 Admin 또는 Accounting 또는 Standard 내가 내 필터 내 논리를하고 프로세스가 계속하도록 할 수 있습니다 경우

[SessionExpireFilterAttribute(UserType = UserTypes.Admin || UserTypes.Accounting || UserTypes.Standard)] 

그런 식으로 예를 들면 다음과 같습니다

는 다음과 같이 설정합니다.

단서가 있습니까?

답변

0

이 같은 뭔가를 그에 대한 배열을 사용할 수 있습니다

[SessionExpireFilterAttribute(UserTypes.Admin, UserTypes.Accounting, UserTypes.Standard)] 

참고 :

public App.Model.UserTypes[] UserTypes { get; set; } 

public SessionExpireFilterAttribute(params App.Model.UserType[] values) { 
    UserTypes = values; 
} 

그런 다음 다음과 같이 사용할 수 있습니다 당신은 params를 사용할 필요가 없습니다 , 너도 할 수있어

[SessionExpireFilterAttribute(new [] {UserTypes.Admin, UserTypes.Accounting, UserTypes.Standard})] 
+0

감사 감사 – VAAA