我正在爲我的ASP MVC 5項目使用MvcSitemapProvider。MvcSitemapProvider在使用currentNode時拋出溢出異常
我已經實現了一個自定義授權,以檢查來自站點地圖的角色是否與用戶角色相同。
這是什麼樣子:
public class CustomAuthorize : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool authorize = false;
var roles = SiteMaps.Current.CurrentNode.Roles;
foreach (var role in roles)
if (System.Web.Security.Roles.IsUserInRole(role))
authorize = true;
return authorize;
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
我的問題是,使用SiteMaps.Current.CurrentNode.Roles
時,它拋出一個An unhandled exception of type 'System.StackOverflowException' occurred in System.Web.dll
,我不知道爲什麼。對象被填充,沒有任何內容爲空。
爲什麼會發生這種情況?現在,我茫然不知如何得到這個工作作爲一個簡單的currentNode不工作...
當你正在調試時,它會到達每個循環還是在之前引發的異常? – Casey
它是在currentNode方法中引發的,它是一個mvcsitemapprovider方法。這就是爲什麼我無能爲力,因爲我無法影響它,也不知道它爲什麼會被拋出。 – Rovdjuret