I have an ASP.NET web site with some locations in the web.config file, e.g.
<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
<% if (UserCanAccessLocation("Somewhere")) { %>
<asp:HyperLink ID="SomeLink" runat="server"
NavigateUrl="~/SomeWhere/">Somewhere</asp:HyperLink>
<% } %>
Is this possible?
The only way i remember – to get SiteMapNode for that url and to use IsAccessibleToUser method to check.