2010-11-08 88 views
1

值如何讀取我的web.config如何閱讀從web.config中

<appSettings> 
<add key="serviceRefPath" value="http://localhost/TempWS/MachineHistoryWS.asmx"/> 
</appSettings> 

應用程序鍵serviceRefPath鑰匙插進我的.aspx頁面中

<asp:ScriptManager ID="sm" runat="server"> 
    <Services> 
     <asp:ServiceReference Path="serviceRefPath here" /> 
    </Services> 
</asp:ScriptManager> 

是否有可能訪問密鑰?先謝謝你。

回答

1

你可以做到這一點的代碼隱藏文件:

sm.Services.Add(new ServiceReference(ConfigurationSettings.AppSettings["serviceRefPath"])); 
1

我最近才知道,你完全可以宣佈你從ASP.net控制代碼隱藏頁,所以你不必擔心字符串文字。

只需創建一個ASP控制面板即可。在代碼隱藏中創建您的ASP.net控件。最後,在生成您的ASP.net控件的代碼的末尾,輸入myPanel.Controls.Add(myControl)