asp.net web api - Reading the web.config file from Global.asax -


i have start code in web api project attempts read values web.config file published inside bin directory default. because application initialization point global.asax, there no web.config @ level need figure out how reference down in bin folder.

here root of iis directory:

root directory of webapi project bound in iis.

anytime try read values web.config file using configurationmanager.appsettings come null. it's when move web.config out of bin folder , root directory values found.

i tried adding code suggested force path correct default location (inside bin folder) before trying read value doesn't work either:

public static class webapiconfig {     public static void register(httpconfiguration config)     {         // fix web.config location         var path = path.combine(appdomain.currentdomain.basedirectory, "bin\\web.config");         appdomain.currentdomain.setdata("app_config_file", path);          var appid = configurationmanager.appsettings["applicationid"];     } } 

is there way force path web.config living inside bin folder?

firstly, not getting why keeping web.config file in bin folder. default path of web.config file same folder global.asax i.e. root directory of application. have been working in asp.net, asp.net webapi , asp.net mvc applications , of them keep web.config in same folder global.asax.

is there lose if move web.config file bin directory same global.asax?

additionally, if connection string want read (as previous question) can below , put connectionsettings in web.config of bin directory.

<connectionstrings configsource="bin\connection.config"/> 

more details regarding configuration files can find in this article.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -