在母版页上填充菜单控件的最佳方法是什么?

发布于 2024-07-05 03:44:59 字数 45 浏览 6 评论 0原文

数据库? 页面变量? 枚举?

我在这里寻求意见。

Database? Page variables? Enum?

I'm looking for opinions here.

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

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

发布评论

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

评论(8

甜嗑 2024-07-12 03:45:00

从用户的角度来看,高效访问是一个主要特征。
通用的暗示方法是
字典查找,
这也非常适合大型和嵌套的菜单结构。
用户通过点击或独特的按键进行导航,另外箭头键像平常一样向上/向下前进(向右)或后退(向左)。 我建议根据请求填充菜单(初始菜单除外),并在选择最终元素时提供 JavaScript 操作。

Efficient access is a primal feature from a user's perspective.
A generic suggestive approach is
dictionary lookup,
that fits well for large and nested menu structures too.
The user navigates by clicks or unique keypresses, additionally arrow keys advance (right) or go back (left) with up/down as usual. I'd suggest to populate the menus on request except the initial one and provide a javascript action, whenever a final element is selected.

欢烬 2024-07-12 03:45:00

这完全取决于网站的运作方式。 我同意大多数人的观点,站点地图通常是最好的方法。 但是,如果您使用 CMS,则可能需要将其保存在数据库中。 如果您有一个以分类为中心的网站,请使用分类来构建菜单。 导航没有“最佳方法”,只有针对特定情况的最佳方法。

It depends entirely on how the site works. I'm in agreement with most that a sitemap is usually the best way to do it. However, if you're using a CMS, then you might need to keep it in the database. If you have a taxonomy-centric site, then use the taxonomy to build the menu. There's no "best way" to do navigation, only the best way for a given situation.

淡写薰衣草的香 2024-07-12 03:45:00

我们有类似的功能。

应用程序菜单从数据库加载到母版页上,因为可见的菜单选项取决于用户的权限。

数据库上的一些约定和巧妙的结构确保菜单加载代码是通用的,并且在选择某个菜单选项时自动导航到正确的屏幕。 我们使用 UIP 进行导航,使用 ComponentArt 进行 Web 控件。

顺便说一句,ComponentArt 很糟糕。 我再次认为所有第三方控件库都是如此。

We've got a similar feature.

The application menu is loaded on the master page from the database, because visible menu options depend on the user's permissions.

A couple of conventions and clever structure on the database ensure that the menu loading code is generic and automagically navigates to the proper screen upon selection of a certain menu option. We use UIP to navigate and ComponentArt for web controls.

BTW ComponentArt sucks. Then again I suppose all third party control libraries do.

月下客 2024-07-12 03:44:59

绑定到站点地图无疑是最简单的。

Binding to a Sitemap is certainly the easiest.

不…忘初心 2024-07-12 03:44:59

如果菜单是动态的每个用户,那么您必须为每个用户访问数据库。 从那时起,我可能会将其存储在会话中,以避免将来与数据库的往返。

如果是动态的,但整个站点看到相同的项目,则将其放入数据库并缓存结果

IF the menu is dynamic per-user then you'll have to hit the database for each user. From then on I would probably store it in session to avoid future round-trips to the database.

If it's dynamic, but the entire site sees the same items, then put it in the database and cache the results

寒江雪… 2024-07-12 03:44:59

这是一个有趣的问题,有很多方法可以解决这个问题。

您可以从 XML 加载菜单结构,这就是内置 ASP.NET 导航控件/“站点地图”设置的工作方式。 总的来说,这可能是一个不错的选择,并且 Visual Studio 中有相当好的工具。

如果它是一个需要进行大量更改的动态菜单,那么从数据库获取项目可能是一个好主意,但您肯定希望缓存它们,这样数据库就不会在每个页面渲染时都受到影响。

That's an interesting question, there are lots of ways to approach it.

You could load the menu structure from XML, that's the way the built-in ASP.NET navigation controls/"sitemap" setup works. This is probably a good choice overall, and there is reasonably good tooling for it in Visual Studio.

If it's a dynamic menu that needs to change a lot, getting the items from a database could be a good idea, but you would definitely want to cache them, so the DB doesn't get hit on every page render.

佼人 2024-07-12 03:44:59

我使用 ASP.NET 登录控件 创建了一个网站,并且ASP.NET Web 应用程序的成员资格/凭据的表单身份验证。 我使用站点地图进行站点导航。

我有使用 SiteMapDataSource 填充的 ASP.NET TreeView 和菜单导航控件。 但仅限管理员访问的禁区页面对非管理员用户可见。

  1. 我创建了一个 web.sitemap 站点地图文件。 我使用了用于设置访问规则的 ASP.NET 网站管理工具

  2. 我在我的 .master 页面上添加了导航控件...

     
       
       
       
       
      
  3. 我在 web.config 文件中将 securityTrimmingEnabled 设置为“true”...

     
      <配置> 
          ... 
          <系统.web> 
              ... 
               
                  <提供商> 
                      <清除>> 
                      <添加名称=“默认” 
                          类型=“System.Web.XmlSiteMapProvider” 
                          siteMapFile="web.sitemap" 
                          securityTrimmingEnabled="true"/> 
                   
               
              ... 
           
          ... 
       
      
  4. 我调整了文件后面的 master.vb 代码中的树...

    Protected Sub TreeView1_DataBound( ByVal sender As Object, ByVal e As EventArgs ) 处理 TreeView1.DataBound 
    
          '折叠不必要的菜单项... 
          如果 TreeView1.SelectedNode 不是什么,那么 
              Dim n As TreeNode = TreeView1.SelectedNode 
              TreeView1.CollapseAll() 
              n.Expand() 
              执行直到 n.Parent 没有任何内容 
                  n = n.父级 
                  n.Expand() 
              环形 
          别的 
              TreeView1.ExpandAll() 
          万一 
    
      结束子 
      

I've created a site using the ASP.NET Login Controls and Forms Authentication for membership/credentials for an ASP.NET web application. And I'm using a site map for site navigation.

I have ASP.NET TreeView and Menu navigation controls populated using a SiteMapDataSource. But off-limits administrator-only pages are visible to non-administrator users.

  1. I created a web.sitemap site map file. And I used the ASP.NET Web Site Administration Tool to set up access rules.

  2. I added navigation controls on my .master page…

    <asp:SiteMapPath ID="SiteMapPath1" runat="server" />
    <asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource2" />
    <asp:TreeView ID="TreeView1" runat="server"  DataSourceID="SiteMapDataSource1" />
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    <asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" ShowStartingNode="False" />
    
  3. I set securityTrimmingEnabled to "true" in my web.config file…

    <?xml version="1.0"?>
    <configuration>
        ...
        <system.web>
            ...
            <siteMap defaultProvider="default">
                <providers>
                    <clear/>
                    <add name="default"
                        type="System.Web.XmlSiteMapProvider"
                        siteMapFile="web.sitemap"
                        securityTrimmingEnabled="true"/>
                </providers>
            </siteMap>
            ...
        </system.web>
        ...
    </configuration>
    
  4. I adjusted the tree in the master.vb code behind file…

    Protected Sub TreeView1_DataBound( ByVal sender As Object, ByVal e As EventArgs ) Handles TreeView1.DataBound
    
        'Collapse unnecessary menu items...
        If TreeView1.SelectedNode IsNot Nothing Then
            Dim n As TreeNode = TreeView1.SelectedNode
            TreeView1.CollapseAll()
            n.Expand()
            Do Until n.Parent Is Nothing
                n = n.Parent
                n.Expand()
            Loop
        Else
            TreeView1.ExpandAll()
        End If
    
    End Sub
    
掀纱窥君容 2024-07-12 03:44:59

The ASP.NET Sitemap feature is built for that and works well in a lot of cases. If you get in a spot where you want your Menu to look different from your Sitemap, here are some workarounds.

If you have a dynamic site structure, you can create a custom sitemap provider. You might get to the point where it's more trouble than it's worth, but in general populating your menu from your sitemap gives you some nice features like security trimming, in which the menu options are appropriate for the logged-in user.

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