简体   繁体   中英

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.

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.

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.

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 .

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.

This gives you a range of options:

Nine Options for Managing Persistent User State in Your ASP.NET Application

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:

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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