允许用户向MenuItem添加新选项 [英] Allow user to add new option to MenuItem

查看:62
本文介绍了允许用户向MenuItem添加新选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个允许用户浏览生产服务器上的特定文件目录的应用程序,我希望用户能够在使用网站时添加其他菜单项,以及创建一个新的菜单项还应该能够指定链接到这个新菜单项的新文件目录值。



有没有办法可以让最终用户动态添加其他项目到这个菜单并设置配置值,而没有单独的管理功能页面来创建新的菜单项?



这里是菜单的设置方式:

I am working on an application that allows users to browse particular file directories on production servers and I would like to allow the user to be able to add additional menu items whilst using the site, as well as creating a new menu item they should also be able to specify a new file directory value linked to this new menu item.

Is there a way that I can allow the end user to dynamically add additional items to this menu and set the config value without having a separate admin functionality page to create the new menu item?

Here''s how the menu is setup:

<table width="100%">
            <tr>
                <td colspan="3" rowspan="1" style="width: 100%; height: 30px" valign="top">
                    <asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2"

                        Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" OnMenuItemClick="Menu1_MenuItemClick"

                        StaticSubMenuIndent="10px" EnableViewState="False" Orientation="Horizontal" Width="100%">
                        <StaticMenuItemStyle BackColor="LightSteelBlue" HorizontalPadding="2px"

                            VerticalPadding="2px" Width="120px" Font-Bold="True" ItemSpacing="1px" />
                        <DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
                        <DynamicMenuStyle BackColor="#B5C7DE" />
                        <StaticSelectedStyle BackColor="#507CD1" ForeColor="White" />
                        <DynamicSelectedStyle BackColor="#507CD1" />
                        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                        <Items>
                            <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>
                            <asp:MenuItem Selectable="False" Text="View Server Items" Value="View Server Items">
                                <asp:MenuItem Text="Browse Inetpub" Value="Inetpub"></asp:MenuItem>
                                <asp:MenuItem Text="Browse SrvApps" Value="SrvApps"></asp:MenuItem>
                                <asp:MenuItem Text="Browse .Net 2.0 64-bit Config" Value="Net20Config64"></asp:MenuItem>
                                <asp:MenuItem Text="Browse .Net 2.0 Config" Value="Net20Config"></asp:MenuItem>
                                <asp:MenuItem Text="View GAC" Value="GAC"></asp:MenuItem>
                                <asp:MenuItem Text="View MSMQ" Value="MSMQ"></asp:MenuItem>
                                <asp:MenuItem Text="Server Time" Value="ServerTime"></asp:MenuItem>
                                <asp:MenuItem Text="Browse Allstate Scripts" Value="AllstateTWSScripts"></asp:MenuItem>
                            </asp:MenuItem>
                            <asp:MenuItem Text="Manage Sites" Value="Manage Sites" Selectable="False">
                                <asp:MenuItem Text="Control Sites" Value="Control Sites"></asp:MenuItem>
                                <asp:MenuItem Text="Control App Pools" Value="Control App Pools"></asp:MenuItem>
                                <asp:MenuItem Text="Download Logs" Value="Download Logs"></asp:MenuItem>
                            </asp:MenuItem>
                            <asp:MenuItem Text="Manage Services" Value="Manage Services"></asp:MenuItem>
                            <asp:MenuItem Selectable="False" Text="Diagnostics" Value="Diagnostics">
                                <asp:MenuItem Text="View EventLog" Value="View EventLog"></asp:MenuItem>
                            </asp:MenuItem>
                        </Items>
                        <StaticHoverStyle BackColor="#284E98" BorderStyle="None" ForeColor="White" Font-Bold="False" />
                        <StaticMenuStyle BackColor="LightSteelBlue" />
                    </asp:Menu>
        <asp:Label ID="lblPath" runat="server" Text="Home" ForeColor="Gray"></asp:Label><span style="color: gray"></span></td>
            </tr>
            <tr>
                <td rowspan="3" style="width: 100%; height: 412px" valign="top" colspan="3">
                    <asp:MultiView ID="MultiView1" runat="server">
                        <asp:View ID="View1" runat="server">
                            <uc3:ucHomeView ID="UcHomeView1"  runat="server" />
                        </asp:View>
                        <asp:View ID="View2" runat="server">
                             <uc8:ucBrowseFiles id="UcBrowseFiles1"  runat="server"></uc8:ucBrowseFiles>
                        </asp:View>
                        <asp:View ID="View3" runat="server">
                            <uc4:ucSites id="UcSites1"  runat="server">
                            </uc4:ucSites>
                        </asp:View>
                        <asp:View ID="View4" runat="server">
                            <uc5:ucServices id="UcServices1"  runat="server">
                            </uc5:ucServices>
                        </asp:View>
                        <asp:View ID="View5" runat="server">
                            <uc6:ucEventLogView id="UcEventLogView1"  runat="server">
                            </uc6:ucEventLogView>
                        </asp:View>
                        <asp:View ID="View6" runat="server">
                            <uc8:ucGacBrowser id="UcGACBrowser1"  runat="server">
                            </uc8:ucGacBrowser>
                        </asp:View>
                        <asp:View ID="View7" runat="server">
                             <uc9:ucAppPools id="UcAppPools1"  runat="server"></uc9:ucAppPools>
                        </asp:View>
                        <asp:View ID="View8" runat="server">
                            <uc10:ucDownloadFile ID="UcDownloadFile1"  runat="server" />
                        </asp:View>
                        <asp:View ID="View9" runat="server">
                            <uc11:ucMSMQBrowser ID="UcMSMQBrowser1"  runat="server" />
                        </asp:View>
                        <asp:View ID="View11" runat="server">
                            <uc12:ucServerTime ID="UcServerTime"  runat="server" />
                        </asp:View>
                    </asp:MultiView> </td>
            </tr>



Web.config Values:


Web.config Values:

<appSettings>
<!--PMC-->
<!--<add key="Inetpub" value="d:\inetpub"/>-->
<add key="Inetpub" value="c:\inetpub"/>
<add key="Srvapps" value="d:\srvapps"/>
<add key="GAC" value="C:\WINDOWS\assembly\GAC"/>
<add key="Net20Config64" value="C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\CONFIG"/>
<add key="Net20Config" value="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG"/>
<add key="AllstateTWSScripts" value="d:\allstate\"/>
<!--PMC-->
<!--<add key="IISLogDir" value="d:\inetpub\LogFiles"/>-->
<add key="IISLogDir" value="c:\inetpub\LogFiles"/>
<!--PMC-->
<!--<add key="IISLogDir2008" value="d:\inetpub\Logs"/>-->
<add key="IISLogDir2008" value="c:\inetpub\Logs"/>
<add key="ViewExt" value=".txt;.log;.config;.ini;.bat;.html"/>
<add key="CleansePasswords" value="false"/>
<!--timeout in seconds-->
<add key="ServiceTimeout" value="30"/>
<add key="ResourceTimeout" value="300"/>
<!--Limit Event Log entries-->
<add key="MaxEvents" value="1000"/>
<add key="MaxRemoteEvents" value="200"/>
</appSettings>

推荐答案

Your menu is defined in the code. You probably don’’t want to allow user to alter code. So change your point of view: you don’’t need to allow user to add menu items, you need to define and put in place a feature that can populate the menu fully or partially in a dynamic manner. You also need to store and retrieve the data of these dynamic items somewhere: in a database for example. Please look at following article for a possible solution: Dynamically populating menu items from the database in ASP.NET[^]
Your menu is defined in the code. You probably don''t want to allow user to alter code. So change your point of view: you don''t need to allow user to add menu items, you need to define and put in place a feature that can populate the menu fully or partially in a dynamic manner. You also need to store and retrieve the data of these dynamic items somewhere: in a database for example. Please look at following article for a possible solution: Dynamically populating menu items from the database in ASP.NET[^]


protected void Page_Load(object sender, EventArgs e)
{
    if (User.IsInRole("admin"))
    {
        mnu.Items.Add(new MenuItem
        {
            Text = "Administer web site",
            NavigateUrl = "~/admin.aspx"
        });
    }
}


这篇关于允许用户向MenuItem添加新选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆