IIS multiple sites use same source

  Due to the business requirement that our site need split 2 sites and 2 database.Therefore, We need to deploy 2 difference folder for sites that are different at the connection string of web.confg.
  At the moment, We just have 2 sites so the deployment jobs are simple.But as time goes it will be increased much of sites some day.By the time, Our deploy job and debug time will be more and difficulty.

Solution
   Putting multiple sites point to the same location.This way is not used the connection string of web.config at its folder but used IIS directly.As below.

1.Web.Release.config used to transform to remove connection string.
This is for removed connection string while it is deployed then used IIS settings.

  <connectionStrings>
    <add name="MyConn" xdt:Transform="Remove" xdt:Locator="Match(name)" connectionString="" />
  </connectionStrings>

2.IIS add Root scope connection string

Production



Stage


When the settings being saved.The settings will be saved at the following path.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config





Besides, it also can be added by PowerShell script.

 Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT' -location ConnIIsLab-PRD' -filter "connectionStrings" -name "." -value @{connectionString='Data Source=.;Initial Catalog=PRD;User ID=sa;Password=xxx';name='MyConn'}
 Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT' -location 'ConnIIsLab-STA' -filter "connectionStrings" -name "." -value @{connectionString='Data Source=.;Initial Catalog=STA;User ID=sa;Password=xxx';name='MyConn'}

Testing
Showing the connection string of each site.
ConnIIsLab-PRD

ConnIIsLab-STA

After-20170815
Many sites point to the same folder while IIS pooling recycling it will sometimes occur the resource locked by another site.Therefore, I separate the folder for each of the sites.

Popular posts from this blog

VS2017-Build fail-FindDependenciesOfExternallyResolvedReferences

IIS Block IP Setting

VS2017.15.8.4 Error fixed