Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using the recommended way to read values from the web.config file (I think). This works fine when using the web server built into Visual Studio but fails if I use the local IIS server. This is the code I am using:

C#
public class Global : System.Web.HttpApplication
{
    protected void Application_Start( object sender, EventArgs e )
    {
        KeyValueConfigurationElement settingKeyValuePair;
        System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "/" );
        settingKeyValuePair = rootWebConfig.AppSettings.Settings[ "DomainForEmails" ];
        var v = settingKeyValuePair.Value;
}


The variable rootWebConfig comes back as NULL. I have no idea why. Any help or advice would be very much appreciated.

Kind wishes, Patrick
Posted

1 solution

Have you set appsetting as:
HTML
<appsettings>
     <add key="XmlFilePath" value="C:\yourpath here" /> 
</appsettings> 

If it is already set, then debug the value on WebConfigurationManger object.
 
Share this answer
 
Comments
Patrick Skelton 17-Mar-12 8:13am    
Hi,

Thank you for the reply.

It is not the reading of a value that fails but the actual reading of the web.config file itself. I can't debug this because, for some reason, I cannot hit a breakpoint in Global.asax (though I can hit breakpoints elsewhere in the same application).

- Patrick

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900