![](/img/trans.png)
[英]ASP.net Call function in Default.aspx.cs from the Site.Master.cs class
[英]How to conditionally suppress an asp:MenuItem from the default ASP.NET Web Site master?
我需要讓一個不專業的人能夠自己安裝ASP.NET應用程序。
安裝程序(一個人)將應用程序文件復制到虛擬目錄中。
安裝程序將獲得適合從sysadmin創建數據庫的SQL Server名稱用戶名和密碼。
該應用程序有一個網頁,它自動在指定的SQL服務器上創建一個空數據庫,其名稱由使用特定Web表單設置服務器名稱的安裝程序提供。
我想讓安裝頁面只出現在主菜單上一次。
安裝頁面在master中有一個鏈接作為asp:MenuItem。
在數據庫安裝后,哪種最簡單的方法可以抑制此菜單項?
我想到了Web.config中的一個特定變量,如果數據庫已經安裝並准備好使用,它將保留值,但有些人不喜歡這個解決方案。
這為您提供了一系列選擇:
您可以使用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");
}
更多信息: http : //msdn.microsoft.com/en-us/library/ms228154.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.