2010-12-19 9 views
0

"SomeController"라는 컨트롤러가 있습니다. 사용자가 로그인했는지 또는 해당 컨트롤러에서 어떤 작업을 실행하기를 원한다면 확인하고 싶습니다. 이렇게하려면, 나는 그 기사 http://blog.wekeroad.com/blog/aspnet-mvc-securing-your-controller-actions/를 읽고 난 내 자신의 클래스 (테스트)를 작성했습니다 :ASP.NET MVC 2 OnActionExecuting 메서드의 문제

public class BaseFilter : ActionFilterAttribute 
{ 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     if (!filterContext.HttpContext.User.Identity.IsAuthenticated) 
     { 
      FormsAuthentication.RedirectToLoginPage(); 
     } 
     //here will be checking the user permissions if he's logged in 
    } 
} 

[BaseFilter] 
public class SomeController : BaseController 
{ 
... 
} 

을하지만, 당신이 이해할 수있는 나는 그 컨트롤러에서 모든 작업을 실행할 때 그것은 부정사 루프를 만든다. 그럼 어떻게 대처할 수 있을까요?

답변

1

조치 필터는 클래스 레벨이 아닌 관련 메소드에 적용 할 수 있습니다.

개인적으로 나는 Authorize과 같은 이름을 지정하고 승인이 필요한 컨트롤러 메서드에 적용합니다.

[Authorize] 
public ActionResult Index() 
{ 
// Do stuff 
}