2013-04-05 45 views
0

這是一個使用Visual Studio 2010的ASPX/CS項目。它是一個Configuration Manager問題。如何在ASPX項目的配置管理器中設置AppSettings

我正在成功調試(有點)一些已經在服務器上使用的代碼。但是有一段代碼與實時版本中的URL一起使用,不應該在debug/localhost版本中使用。

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (ConfigurationManager.AppSettings["IsTesting"] == "false" && Request.Url.ToString().Contains("http:")) 
     { 
      Response.Redirect(Request.Url.ToString().Replace("http:", "https:")); 
     } 

     LoadMasterTemplate(); 
    } 

這片土地上的代碼上的「Response.Redirect的......」行,當它不應該因爲「IsTesting」應用程序設置應在ConfigurationManager設置爲true。我如何設置?

回答

1

裏面在App/Web.config文件中<configuration>元素,應該有(或者你應該創建)一個<appSettings></appSettings>標籤,和個人設置看起來有點像這樣:

<appSettings> 
    <add key="NewKey0" value="Something1" /> 
    <add key="NewKey1" value="Something2" /> 
</appSettings> 
+0

你是對的。我在web.config文件中找到了這個: xarzu 2013-04-05 02:22:57

1

「ConfigurationManager中」看的「web.config」爲ASP.Net解決方案,所以你可以找到它無論是在:

<configuration> 
    <appSettings> 
    <add key="IsTesting" value="true"/> 
    </appSettings>  
</configuration> 

或者,如果你訪問IIS管理器並選擇網站,然後點擊「應用程序設置」,你可以改變它通過GUI。

相關問題