简体   繁体   中英

Conditional location authorization in web.config?

In IIS 7.5 web.config we can set authorization for various paths/folders like so:

<location path="logs/elmah/elmah.axd">
    <system.web>
      <authorization>
        <allow users="bob@example.com" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>

Is it possible to make this authorization conditional? eg only use this location if it is the live server, not the local or staging or beta or etc server?

I use this to indicate what the current server is:

<appSettings>
    <clear />
    <add key="DeploymentEnv" value="Debug" />
</appSettings>

And then web.config transforms to change DeploymentEnv to the correct value.

Having different Web.config files for different environments it's probably the right way. Have a look at Web.config transformations . This MSDN article shows how to configure a staging configuration.

If you are going to have conditional web.config files dependent on environment what is it going to look for? Machine name? IP address? Having conditions to pick the right one could get messy and hard to maintain.

Easiest is to have two or more config files for each of your environments. There maybe mor tags you need to add to your config file later on that is specific to the environment. Having seperate config files helps you manage these changes. Make sure name them appropriately eg production.config uat.config, etc. and just rename them to web.config when you are moving it to a different environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM