[英]System.Security.SecurityException - Get the role name
我已經在我的global.asax中實現了一個捕獲所有安全異常的方法,如下所示...
protected void Application_Error(object sender, EventArgs e)
{
Exception err = Server.GetLastError();
if (err is System.Security.SecurityException)
Response.Redirect("~/Error/Roles.aspx);
}
我是否可以訪問一個屬性,該屬性顯示用戶權限中缺少的角色的名稱? 就是 err.RoleThatFailed?
謝謝,
ETFairfax。
您可以只輸出整個stacktrace。
即
err.ToString()
將告訴您更多信息。
可以在PermissionState屬性中找到該角色。 此屬性包含需要解析的XML。 角色名稱可以在元素“ 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.