0

내 C# MVC4 응용 프로그램에서 Active Directory와 함께 폼 기반 인증을 사용하고 있습니다. 맞춤 광고 회원 제공자가 있습니다. 필자는 사용자가 속한 그룹을 읽고 확인할 수 있음을 성공적으로 테스트했습니다. 이제 필자는 다음을 수행하는 사용자의 권한 부여 속성을 만들려고 :MVC4 폼 인증 Active Directory 사용자 지정 인증 특성

여기
if (user is logged-in/not timed-out/authenticated) 
{ 
    if (user's role is equal to role 1 or role 2) 
     { 
     return a specific view or (preferably) perform a specific redirect to action 
     } 
    else 
     { 
     return a different specific view or (preferably) perform a different specific  redirect to action 
     } 
} 
else 
    {  
    return View 
    } 

내가 지금까지 무엇을 가지고 :

public class AuthorizeEditAttribute : AuthorizeAttribute 
    { 
     protected override bool AuthorizeCore(HttpContextBase httpContext) 
     { 
      if (httpContext.Request.IsAuthenticated) 
      { 
       if ((httpContext.User.IsInRole("group1")) || (httpContext.User.IsInRole("group2"))) 
       { 

        return true; 
       } 
       else 
       { 
        return false; 
       } 
      } 
      else 
      { 
       return false; 
      } 
} 

나는 또한 리디렉션 작업을 수행하는 방법을 알아낼 질수. 나는 post에서 리디렉션을 수행하는 방법을 논의했지만 지금까지 내가 가지고있는 것과 이것을 어떻게 통합 할 수 있는지 이해하지 못한다. 특히 나는 내가 수행하는 첫 번째 점검을 위해 httpcontext.user에 대한 액세스 권한을 얻기 위해 AuthorizeCore를 사용해야한다고 믿기 때문에 AuthorizationContext 유형에 대한 다른 매개 변수를 전달하는 방법을 알지 못합니다. AuthorizationContext는 원하는 경로를 따라 전달되는 것으로 보이는 것을 수행하는 데 필요합니다. 리디렉션.

+0

도움이 될만한 지 확인하십시오. [http://stackoverflow.com/questions/35120816/mvc4-and-ef5] -with-active-directory-authentication-and-roles-in-sql] (http://stackoverflow.com/questions/35120816/mvc4-and-ef5-with-active-directory-authentication-and-roles-in- SQL) – user2988717

답변

1

나는 또한 OnAuthorization 메서드를 덮어 써야한다고 생각합니다. 여기에는 AuthorizationContext 매개 변수가있어서 결과를 RedirectResult으로 설정할 수 있습니다 ...