根据 Roles/Web.sitemap 文件显示/隐藏自定义菜单项

发布于 2024-08-24 16:41:33 字数 828 浏览 2 评论 0原文

我有一个自定义菜单,它利用标准的 asp.net 站点地图。它运行良好,但我的一些页面是由 URL 重写器动态生成的,因此它们不位于站点地图 XML 文件中。目前,我推出了一个自定义解决方案,它通过 CSS 类显示/隐藏菜单项,并以编程方式检查用户所处的角色。它可以正常工作,直到我访问站点地图文件中不存在的动态页面。我已尝试使用站点地图文件中的“角色”属性进行安全修剪,但它不起作用,因为我有一个自定义菜单。

有没有办法利用站点地图文件中的角色属性来显示/隐藏下面的自定义控件的菜单项,即使某些页面不在站点地图中?我的菜单控件如下...

<div class="menu">
<ul>
    <asp:Repeater ID="rpt" runat="server" DataSourceID="smdsMenuPrimary" 
        EnableViewState="False">
        <ItemTemplate>                
            <li class="<%#GetDisplayClass((SiteMapNode)Container.DataItem)%>"><a href='<%# ((SiteMapNode)Container.DataItem).Url %>'><%# ((SiteMapNode)Container.DataItem).Title %></a></li>                
        </ItemTemplate>
    </asp:Repeater>
</ul>

I have a custom menu, which leverages the standard asp.net sitemap. It works well but some of my pages are dynamically generated by URL rewriter, so they don't sit in the sitemap XML file. At the moment I rolled a custom solution which shows/hides menu items via CSS class and a programmatic check of the role that the user is in. It works ok until I visit a dynamic page that doesn't exist in the sitemap file. I've tried the "roles" attribute in the sitemap file with security trimming but it isn't working because I have a custom menu.

Is there a way I could leverage the roles attribute in the sitemap file to show/hide menu items for my custom control below, even when some pages are not in the sitemap? My menu control is below...

<div class="menu">
<ul>
    <asp:Repeater ID="rpt" runat="server" DataSourceID="smdsMenuPrimary" 
        EnableViewState="False">
        <ItemTemplate>                
            <li class="<%#GetDisplayClass((SiteMapNode)Container.DataItem)%>"><a href='<%# ((SiteMapNode)Container.DataItem).Url %>'><%# ((SiteMapNode)Container.DataItem).Title %></a></li>                
        </ItemTemplate>
    </asp:Repeater>
</ul>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2024-08-31 16:41:33

您可以使用 UrlAuthorizationModule.CheckUrlAccessForPrincipal(path) 来测试站点地图中的每个 URL - 如果用户有权访问该路径(文件或文件夹),则此方法返回 true,否则返回 false。

You can use UrlAuthorizationModule.CheckUrlAccessForPrincipal(path) to test each URL from the site map - this method returns true if user has access to the path (file or folder) and false otherwise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文