2014-01-22 2 views
0

ASP.NET MVC에 문제가 있습니다. 데이터베이스에서 각 작업 및 각 컨트롤러에 대한 역할을 가져 오기 위해 사용자 지정 AuthorizeAttribute를 만들었습니다. 여기 권한 부여 특성 및 캐시 관련 문제

코드입니다 :

public class CustomAuthAttribute : AuthorizeAttribute 
{ 
    private string[] _roles; 
    private Db_Entities db = new Db_Entities(); 
    private String controller; 
    private String action; 

    public CustomAuthAttribute(String controller, String action) 
    { 
     this.controller = controller; 
     this.action = action;   
    } 


    protected override bool AuthorizeCore(HttpContextBase httpContext) 
    { 
     if (httpContext == null) 
     { 
      throw new ArgumentNullException("httpContext"); 
     } 

     Actions myAction = db.Actions.Where(a => a.Libelle.Equals(this.action)).Single(a => a.Controller.Equals(this.controller)); 
     List<String> myGroupeList = new List<String>(); 
     foreach (Groupes g in myAction.Groupes) 
     { 
      myGroupeList.Add(g.Groupe); 
     } 
     this._roles = myGroupeList.ToArray<string>(); 

     IPrincipal user = httpContext.User; 
     if (!user.Identity.IsAuthenticated) 
     { 
      return false; 
     } 

     bool isAuthorized = false; 

     RoleProviderAD rp = new RoleProviderAD(); 
     string[] DbRoles = rp.GetRolesForUser(httpContext.User.Identity.Name); 
     foreach (string str in DbRoles) 
     { 
      if (this._roles.Contains(str)) 
      { 
       isAuthorized = true; 
      } 
     } 
     return isAuthorized; 
    } 

} 

'홈'컨트롤러 '지수'액션이 호출되면, AuthorizeCore 너무이라고 및 사용자 권한에 관한 datas가 데이터베이스에서 붙잡힌 다. 그러나 데이터베이스에서 데이터를 변경하면이 페이지를 다시 호출 할 때 코드가 다시 실행되어야하는 것처럼 보이지만 이전 데이터가 캐치됩니다.

나는 ActionFilterAttribute를 사용하려고했지만 순서 때문에 작동하지 않습니다. 또한 IIS 서버에 몇 가지 규칙을 추가하려고했습니다. 모든 것이 실패했습니다. 누군가 나를 도울 수 있다면, 좋을 것입니다!

답변

0

당신이 아약스 호출

$.ajaxSetup({ cache: false }); 
+0

당신이 당신의 메서드를 호출하는 방법이 작업 –

+0

에 대한 Ajax 호출이 없습니다 전에이 코드를 포함하는 모든 아약스 calls.Try를 사용하는 경우? – Sajeev

+0

이 경우 간단한 링크입니다 : Html.ActionLink ("Accueil", "Index", "Home") –