[英]ASP.NET: show or hide a link in a page according to location configuration in web.config file
I have an ASP.NET web site with some locations in the web.config file, eg 我有一个ASP.NET网站,在web.config文件中有一些位置,例如
<location path="SomeWhere">
<system.web>
<authorization>
<allow roles="some-role"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
Then, in the master page for the site, I have a set of links, and I would like to show or hide some of the links according to the user's roles. 然后,在网站的主页中,我有一组链接,并且我想根据用户的角色显示或隐藏一些链接。 I am currently doing this: 我目前正在这样做:
<% if (HttpContext.Current.User.IsInRole("some-role")) { %>
<asp:HyperLink ID="SomeLink" runat="server"
NavigateUrl="~/SomeWhere/">Somewhere</asp:HyperLink>
<% } %>
I would like to avoid duplicating the role information in the web.config file and in the page code, and to replace the above check with something like 我想避免在web.config文件和页面代码中重复角色信息,而将上述检查替换为类似
<% if (UserCanAccessLocation("Somewhere")) { %>
<asp:HyperLink ID="SomeLink" runat="server"
NavigateUrl="~/SomeWhere/">Somewhere</asp:HyperLink>
<% } %>
Is this possible? 这可能吗?
我记得的唯一方法-获取该URL的SiteMapNode并使用IsAccessibleToUser方法进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.