2009-10-30 3 views
0

내 global.asax에서 catch 모든 보안 예외 메서드를 구현했습니다 ...System.Security.SecurityException - 롤명을 취득한다

protected void Application_Error(object sender, EventArgs e) 
    { 

     Exception err = Server.GetLastError(); 
     if (err is System.Security.SecurityException) 
      Response.Redirect("~/Error/Roles.aspx); 

    } 

사용자 권한에서 누락 된 역할의 이름을 표시 할 수있는 액세스 할 수있는 속성이 있습니까? 예. 알았어?

감사합니다.

ETFairfax.

답변

0

전체 스택 추적을 출력 할 수 있습니다.

즉,

err.ToString() 당신에게 더 많은 정보를 알려드립니다.

+0

답장을 보내 주셔서 감사합니다. 나는 사용자가 보는 페이지에 좀더 구체적이되고 싶었다. I.E "허가 XYZ"가 없습니다. err.ToString()이 내 오류 로그로 이동하여 어떤 일이 발생했는지 알 수 있지만 사용자가 좀 더 친숙한 것을 볼 필요가 있습니다! – ETFairfax

0

역할은 PermissionState 속성에서 찾을 수 있습니다. 이 속성에는 구문 분석해야하는 XML이 포함되어 있습니다. 역할 이름은 'Identity'요소에서 찾을 수 있습니다. 'Identity'요소에는 'Role'이라는 속성이 있습니다.

Exception err = Server.GetLastError(); 
if (err is System.Security.SecurityException) 
{ 
    var xmlDocument = new XmlDocument(); 
    xmlDocument.LoadXml(err.PermissionState); 
    string roleName = xmlDocument.GetElementsByTagName("Identity")[0].Attributes["Role"].Value; 

    ... 

    Response.Redirect("~/Error/Roles.aspx);  
}