4
votes

How can I have different Web.config files for different Azure slots.

I have a staging and production slot with the same website I don't want the staging slot to be public (it's only for testing and such), so I've setup authentication for that slot through the web.config file.

The problem is that when I upload changes the production slot gets the same web.config file as the staging slot which is set for only allowing access by authenticating, and also the parameters are different so the production slot ends up getting inaccessible, I have to change the web.config file manually in the production slot to make it work.

I wanted to have some way to define a different web.config file for the production slot.



Update (adding more information to the question):

I'm using my local machine for testing (with a local server), that is the development environment.
The sites are in wordpress (wordpress uses php).

The staging slot is used only by a few people, not connected to my local Lan, when I selectively want them to test my site (different Operating Systems, different platforms, different mobile phones,..) before sending things to production. I can just stop the staging slot, when I'm not using it so production resources are not be affected.
I'm already using AppSettings for different connectionStrings, and parameters. I don't know how to use this to define different authentication settings..? I have the authentication settings in the web.config file (used by the staging slot).

My web.config file:

<configuration>
  <system.web>
    <authorization>
      <allow users="[email protected], [email protected], [email protected]"/>
      <deny users="*"/>
    </authorization>
  </system.web>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="WordPress: http://contoso.azurewebsites.net" patternSyntax="Wildcard">
          <match url="*"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Rewrite" url="index.php"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
2

2 Answers

1
votes

You are using slots incorrectly. Staging slots are not meant to be long-lived applications for testing. These are for deployment and short-automated testing of the application while you are deploying.

Also if your prod and staging slots are almost identical, what is the point of securing staging if it does the same thing as production?

And to conclude - there is no way to do what you want to do. So you might as well set up separate testing WebApp and get it secured via web.config.

0
votes

There are a few ways to accomplish what you are trying to do. Although I agree with Trailmax - this seems to be a misuse of the intended purpose of slots. Remember that slots share resources (CPU, memory, etc) with your production slot. If you're using a slot for your integration and testing environments and something goes sideways, you are impacting your production resources. That's really not a good idea.

But if you want to go this route anyways, you can:

  1. Use slots along with different build configurations and associated web.config transforms. For example, if your production site is foo.azurewebsites.net, you can define a staging slot called "staging". You can publish directly to that slot at foo-staging.azurewebsites.net. Define a separate build configuration called Staging, and create a web.staging.config transform that updates the underlying web.config to the values you want to deploy to your staging slot. Make sure that when you publish, you choose the foo-staging target, and that you choose "staging" as your build configuration.

  2. If the environments differ by AppSettings and ConnectionStrings, define slot-specific values in the Web App's Application Settings section. These override whatever is in web.config. This is my personal favorite approach.