ASP.NET OpenWebConfiguration failing

I’m trying to open the web configuration so I can encrypt/decrypt it but it’s failing. I’m doing this on Web Developer 2010 Express on my desktop where I setup a website as a filesystem. Here are the ways I’ve tried.

Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);

Configuration config = WebConfigurationManager.OpenWebConfiguration("~");

Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

Configuration config = WebConfigurationManager.OpenWebConfiguration("/web.config");

Configuration config = WebConfigurationManager.OpenWebConfiguration(/AppNameHere);

Every time I get error: An error occurred loading a configuration file: Failed to map the path ‘/’.

Any ideas?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you are trying to open the web.config from within the application, you don’t need to open it, just use:

var section = WebConfigurationManager.GetSection("mySection");

Just for you to know, the right parameter is:

Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");

See: http://msdn.microsoft.com/es-es/library/system.web.configuration.webconfigurationmanager(v=vs.100).aspx

Method 2

Run your Visual Studio as Administrator. Cheers! 😀


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x