views:

162

answers:

4

How could you do to read a web.config file from inside a aspx file?

Thanks!

+1  A: 

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]
Anthony Pegram
+5  A: 

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>
....
Glennular
+1 WebConfigurationManager (from System.Web.Configuration) is the correct object to use in ASP.NET, not ConfigurationManager
PhilPursglove
Thanks, I got it to work like that, just had to add the full name :P
Francisco Noriega
+1  A: 
ConfigurationManager.AppSettings["YourPropertyHere"];

as in

string connectionString = ConfigurationManager.AppSettings["MyConnectionString"];
Leniel Macaferi
A: 

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

Dal