SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    web.config Customization

    Is there an easy way to configure the web.config so that you can separate those settings that you want to apply when developing locally and those that you want to use when the application is deployed?

    For instance, I have to remember to change several things when I upload my code to the server including ConnectionStrings, settings pertaining to Advertisements, etc. It'd be nice if I could just upload the web.config to the server and it would realize it needs to use certain settings. Even if I only had to change a single flag in the web.config that would help eliminating forgetting to change a certain settings.

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    There are a number of ways to skin this cat. If you use Web Deployment projects, you can make tweaks to web.config in the deployment package. Personally I tend towards using different configurations to copy in different copies of configuration files as appropriate.

  3. #3
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    There are a number of ways to skin this cat. If you use Web Deployment projects, you can make tweaks to web.config in the deployment package. Personally I tend towards using different configurations to copy in different copies of configuration files as appropriate.
    Currently I"m just copying my files to the server using ftp, is that bad?

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it's not bad, it is the most simple way to synch a site and it does work as expected.

    There are multiple ways you can achieve something like this without the need for a deployment project. It does have a certain "basic" feel just being able to upload/synch the files.

    If you look at web.config, the individual sections can be delegated/teared out into seperate files. All sections support a configSource="filename" attribute. This prompts ASP.NET to read the section from that file instead. Thus you can take the connectionStrings section and delegate to an "external" file which you then exclude from synchronisation when you update the site. You would need to have a seperate file for each section you want to tear off like this, though.

    An alternative is to use the <location> element in a site- or server wide web.config file. Inside this element you can have sections with connectionStrings etc. which are then inherited by the site. If the site does not override or change the section it will simply use these values. This way you can externalize the environment dependant configuration settings.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •