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.

   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.

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

2.IIS add Root scope connection string



When the settings being saved.The settings will be saved at the following path.

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'}

Showing the connection string of each site.


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

SQL Server pass parameter to Procedure

IIS Block IP Setting