我在我的web.config以下:在我的codebehind類中,如何檢索授權角色?
<location path="RestrictedPage.aspx">
<system.web>
<authorization>
<allow roles="Group1Admin, Group3Admin, Group7Admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
在RestrictedPage.aspx.cs,我該如何找回允許的角色集合,其中包含Group1Admin,Group3Admin和Group7Admin?
這就是爲什麼我問:
web.config中被處理的授權頁面。這工作正常。但是我將有幾個這樣的頁面(比如說RestrictedPage.aspx,RestrictedPage2.aspx,RestrictedPage3.aspx)。這些頁面中的每一個都會有我的自定義webcontrol。每個頁面都有不同的角色。我的webcontrol有一個下拉列表。下拉菜單中的選項取決於用戶角色與頁面允許角色的交集。
如下所述,使用XPath搜索web.config可能會起作用。我只是希望有更多的框架。有點像SiteMap。當我將角色放入web.sitemap時,我可以使用SiteMap.CurrentNode.Roles(我的網站使用Windows身份驗證,因此我無法使用web.sitemap進行安全修整,我寧願只保留一個角色文件)。
完美!這是我的最後一行: AuthorizationSection section =(AuthorizationSection)WebConfigurationManager.GetSection(「system.web/authorization」,Request.Path); Request.Path導航到location =「RestrictedPage.aspx」(當它是當前頁面)。 謝謝! – 2008-10-20 13:30:13