简体   繁体   English

如何从默认的ASP.NET网站主文件有条件地抑制asp:MenuItem?

[英]How to conditionally suppress an asp:MenuItem from the default ASP.NET Web Site master?

I need to let an unprofessional to be able to install an ASP.NET application by himself. 我需要让一个不专业的人能够自己安装ASP.NET应用程序。

The installer (a person) will copy the application files into a virtual directory. 安装程序(一个人)将应用程序文件复制到虚拟目录中。

The installer will get a SQL server name username and password suitable for creating a database from the sysadmin. 安装程序将获得适合从sysadmin创建数据库的SQL Server名称用户名和密码。

The application has a web page which is automatically creating an empty database on a designated SQL server which its name is given by the installer who is setting the server's name using a specific web-form. 该应用程序有一个网页,它自动在指定的SQL服务器上创建一个空数据库,其名称由使用特定Web表单设置服务器名称的安装程序提供。

I would like to have the installation page to appear on the master menu only once. 我想让安装页面只出现在主菜单上一次。

The installation page has a link in the master as an asp:MenuItem . 安装页面在master中有一个链接作为asp:MenuItem。

Which is the best SIMPLE way to suppress this menu item after the database installation? 在数据库安装后,哪种最简单的方法可以抑制此菜单项?

I thought of a specific variable in Web.config, which will hold the value stating if the database is already installed and ready to be use or not, but some doesn't like this solution. 我想到了Web.config中的一个特定变量,如果数据库已经安装并准备好使用,它将保留值,但有些人不喜欢这个解决方案。

This gives you a range of options: 这为您提供了一系列选择:

Nine Options for Managing Persistent User State in Your ASP.NET Application 在ASP.NET应用程序中管理持久用户状态的九个选项

You could use the appSettings section in the Web.Config file to generate variables at project or folder level and cache the vars for the duration of the session: 您可以使用Web.Config文件中的appSettings部分在项目或文件夹级别生成变量,并在会话期间缓存变量:

<appSettings>
    <add key="customsetting1" value="Some text here"/>
</appSettings>

System.Configuration.Configuration rootWebConfig1 =                  
    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

if (rootWebConfig1.AppSettings.Settings.Count > 0)
{
    System.Configuration.KeyValueConfigurationElement customSetting = 
        rootWebConfig1.AppSettings.Settings["customsetting1"];
    if (customSetting != null)
        Console.WriteLine("customsetting1 application string = \"{0}\"",   
            customSetting.Value);
    else
        Console.WriteLine("No customsetting1 application string");
}

More info: http://msdn.microsoft.com/en-us/library/ms228154.aspx 更多信息: http//msdn.microsoft.com/en-us/library/ms228154.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM