can't find 'current' web.config with OpenWebConfiguration

T

Tim_Mac

hi,
i'm trying to read the system.web section of the web.config in my web
application.
the problem is that the configuration returned is not the one in my
application root.
i've tried all sorts of variations to load my web.config, but they are
not picking up the right version of web.config.

this is the code i'm using:

Configuration config =
WebConfigurationManager.OpenWebConfiguration("~");
SystemWebSectionGroup systemWeb = config.GetSectionGroup("system.web")
as SystemWebSectionGroup;
return
systemWeb.SiteMap.Providers[0].ElementInformation.Properties["siteMapFile"].Value.ToString();

the correct value should be 'App_Data/web.sitemap' but it is always
returning 'web.sitemap' which is in the global web.config.

any ideas? i don't want to hard code the name of the web site that i
have deployed to, as this could easily change. i just want the
'current' web.config.

thanks
tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top