开发者

How to read values from web.config

开发者 https://www.devze.com 2023-01-24 03:09 出处:网络
How to read the app key servic开发者_Python百科eRefPath key in my web.config <appSettings> <add key=\"serviceRefPath\" value=\"http://localhost/TempWS/MachineHistoryWS.asmx\"/>

How to read the app key servic开发者_Python百科eRefPath key in my web.config

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

into my .aspx page

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

Is it possible to access the key? Thank you in advance.


You can do it in code-behind file:

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


I learnt recently that you can declare you ASP.net control entirely from the code-behind page so you don't have to worry about the string literals at all.

Simply create an ASP panel where you want the control to go. Create your ASP.net control in codebehind. Finally, at the end of the code to generate your ASP.net control, put myPanel.Controls.Add(myControl).

0

精彩评论

暂无评论...
验证码 换一张
取 消