Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get current config of the web application without using HttpContext?

I need to get the instance of current configuration in my web application. I found that I can get it in the following way:

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

But in some parts of my project I have no HttpContext so I need to get the instance of the config without using the HttpContext.

like image 831
Andrew Lubochkn Avatar asked Nov 08 '11 15:11

Andrew Lubochkn


2 Answers

you right Lubochkn ~ does the trick...

_webConfigurationManager = WebConfigurationManager.OpenWebConfiguration("~");
like image 86
Sebastian Castaldi Avatar answered Oct 13 '22 13:10

Sebastian Castaldi


You should be able to get the web.config like this too:

Configuration config = WebConfigurationManager.OpenWebConfiguration("/");
like image 24
James Johnson Avatar answered Oct 13 '22 13:10

James Johnson