Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connectionstring declare in iis without declaring in web.config

I want to declare my connection string in IIS and get it from there. I don't want to declare it in web.config page. Rather I need to know if is it possible to get the string from iis in web.config or read it from code file. I am using asp.net 4.0.,coding in c# and server is IIS7.5

like image 806
polin Avatar asked Jul 04 '13 11:07

polin


1 Answers

According to this article you can use the IIS UI, or the command line to modify your connection string, but this will just write into the <connectionString> element in the web.config file any way (unless you've set it up to save elsewhere).

Also, you can store it in another .config file if you wish, and pull it into your web.config like so

<appSettings file="../VirtualDirectory/config/Env.config">
</appSettings>

You could then call it like so in your code:

System.Configuration.ConfigurationManager.AppSettings["DefaultConn"]

This can be quite useful if you want the location of your connection string to not be under your site (i.e. in a virtual directory).

like image 159
Mike B Avatar answered Oct 14 '22 00:10

Mike B