Set header from URL Rewrite on Azure Websites - AppCmd or applicationhost.config?

徘徊边缘 提交于 2019-12-24 11:37:48

问题


I'd like to set a request header (HTTP_HOST to be precise) from Web.config, using the IIS URL Rewrite module, on Azure Websites. Basically I'd like to have something like this in my site's Web.config:

<system.webServer>
  <rules>
    <clear />
    <rule name="My rule" enabled="true">
      <match url=".*" />
      <serverVariables>
        <set name="HTTP_HOST" value="my value" />
      </serverVariables>
      <action type="None" />
    </rule>

This results in an error that HTTP_HOST is not allowed to be set. This is normal and with standard IIS the next step would be to add HTTP_HOST to the <allowedServerVariables> element to applicationhost.config directly or through AppCmd. However I couldn't find any hints on being able to access this config somehow.

Is it possible to somehow modify the apphost config, or add allowed server variables somehow else?


回答1:


This answer was out of date (and should be deleted).




回答2:


It is possible to alter Azure's ApplicationHost.config by applying xdt transformations.

Upload the file to the /site and restart your site for the changes to to take effect:

ApplicationHost.xdt

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.webServer>
      <rewrite>
        <allowedServerVariables>
          <add name="HTTP_HOST" xdt:Transform="Insert" />
        </allowedServerVariables>
      </rewrite>
    </system.webServer>
</configuration>

See also:

  1. https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples
  2. http://azure.microsoft.com/nl-nl/documentation/articles/web-sites-transform-extend/


来源:https://stackoverflow.com/questions/21666481/set-header-from-url-rewrite-on-azure-websites-appcmd-or-applicationhost-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!