简体   繁体   中英

C# setting web.config according to machine name

Is it possible to change web.config (ASP.NET c#) file depending on Environment.MachineName? For example if I am running WebApp1 on dev.internal.net machine I need a connectionstring1 and webapp2 on Prod.external.net it is connectionstring2?

Thanks R

You can make several different connection strings like this:

    <add name="dev.internal.net" connectionString="Data Source=Location DB1;Initial       Catalog=DB Name;Integrated Security=True"/>
    <add name="Prod.external.net" connectionString="Data Source=Location DB1;Initial       Catalog=DB Name;Integrated Security=True"/>

You can make the name of the connection string as the Environment.MachineName to make it work.

Some more information is on the following link:

http://ayende.com/blog/135169/frictionless-development-web-config-and-connection-strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM