Deploy without overwriting Web.Config

D

dev648237923

I develop my application on my dev server and then I deploy it to a
customer's production server. I store the db connection string in web.config
(is this best practice?). When I deploy I have to open the production
web.config and change the connection string to the correct one for
production. Now I want my customer to keep their sql server
username/password secret. They are unable/unwilling to change the web.config
each time I make an update to the app. How can I deploy my app without
having to access their web.config (each time I deploy it overwrites
web.config). There must be a way a dev can make an asp.net app and deploy it
it to a server without always knowing and having to change the connection
string. Thanks for any ideas!
 
M

Mark Rae

I develop my application on my dev server and then I deploy it to a
customer's production server. I store the db connection string in
web.config (is this best practice?). When I deploy I have to open the
production web.config and change the connection string to the correct one
for production. Now I want my customer to keep their sql server
username/password secret. They are unable/unwilling to change the
web.config each time I make an update to the app. How can I deploy my app
without having to access their web.config (each time I deploy it overwrites
web.config). There must be a way a dev can make an asp.net app and deploy
it it to a server without always knowing and having to change the
connection string. Thanks for any ideas!

http://msdn2.microsoft.com/en-us/asp.net/aa336619.aspx
 
W

Walter Wang [MSFT]

Hi,

Every config section has an optional attribute named "configSource" to
point to an external file. Therefore you could break down your web.config
into several files and update them accoringly:

web.config:

...
<configuration>
<appSettings/>
<connectionStrings configSource="connectionStrings.config"/>
<system.web>
...



connectionStrings.config:

<connectionStrings>
<add name="NorthwindConnectionString" connectionString="..."
providerName="System.Data.SqlClient" />
</connectionStrings>


For more information:

======================
#General Attributes Inherited by Section Elements
http://msdn2.microsoft.com/en-us/library/ms228167.aspx

configSource
Optional String attribute.

Specifies the name of the include file in which the associated
configuration section is defined, if such a file exists.
======================

Also as Mark suggested, Web Deployment Project add-on could help you do the
deploy and merging automatically.


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

dev648237923

Hi --

The problem I see with using a connectionStrings.config file is that it
appears that that file must reside in the app's dir or a subdir of it.
Whenever I redeploy the app that dir and its subdirs are deleted so I am
back to the same problem. Is there a way to have connectionStrings.config in
say c:\inetpub\securedir\connectionStrings.config and then have my app's
web.cofig reference that?
Thank you.
 
W

Walter Wang [MSFT]

Hi,

Yes unfortunately the configSource attribute must be a relative physical
path. Both the default publishing tool and the Web Deployment Project
add-on will first delete the target directory before deploying, therefore
it's impossible to prevent some file in the target directory from being
updated.

As a workaround, I suggest:

1) first publish (either the default publish tool or WDP) to a temporary
place
2) use some script to backup the connectionStrings.config from the target
directory
3) delete all files in the target directory
4) move the files from the temporary directory to the target directory
5) restore the connectionStrings.config back to the target directory

Hope this helps.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top