2010-11-08 45 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)