开发者

How to read configuration file from a ASPX?

开发者 https://www.devze.com 2022-12-26 02:12 出处:网络
How could you do to read a web.config开发者_开发百科 file frominside a aspx file? Thanks!I assume you want to read the AppSetting parts of the web.config. Each diffrent area of the web.config file ge

How could you do to read a web.config开发者_开发百科 file from inside a aspx file?

Thanks!


I assume you want to read the AppSetting parts of the web.config. Each diffrent area of the web.config file gets loaded a different way. But the appSetting are intended for user variables.

WebConfigurationManager.AppSettings["VariableName"];

<configuration>
    <configSections>
    <appSettings>
        <add key="VariableName" value="xxxx"/>
    </appSettings>
....


Are you trying to check application settings? Connection strings?

Go through System.Configuration.ConfigurationManager

.AppSettings[int index or string name]
.ConnectionStrings[int index or string name]


ConfigurationManager.AppSettings["YourPropertyHere"];

as in

string connectionString = ConfigurationManager.AppSettings["MyConnectionString"];


If your after the AppSetting section (name/value pairs) then this article will show you a good example of how to read them:

http://odetocode.com/Articles/345.aspx

0

精彩评论

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