Asp.net 从Azure网站上的URL重写设置标题-AppCmd或applicationhost.config?
我想在Azure网站上使用IIS URL重写模块从Web.config设置请求头(确切地说是HTTP_主机)。基本上,我希望在我的网站的Web.config中有类似的内容:Asp.net 从Azure网站上的URL重写设置标题-AppCmd或applicationhost.config?,asp.net,azure,azure-web-app-service,url-rewrite-module,Asp.net,Azure,Azure Web App Service,Url Rewrite Module,我想在Azure网站上使用IIS URL重写模块从Web.config设置请求头(确切地说是HTTP_主机)。基本上,我希望在我的网站的Web.config中有类似的内容: <system.webServer> <rules> <clear /> <rule name="My rule" enabled="true"> <match url=".*" /> <serverVariable
<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>
这将导致一个错误,即不允许设置HTTP_主机。这是正常的,对于标准IIS,下一步是直接或通过AppCmd将HTTP\U主机添加到applicationhost.config的
元素中。然而,我找不到任何关于以某种方式访问此配置的提示
是否可以以某种方式修改apphost配置,或以其他方式添加允许的服务器变量?此答案已过时(应删除)。可以通过应用xdt转换来更改Azure的ApplicationHost.config 将文件上载到/站点并重新启动站点,以使更改生效: 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>
,您应该使用xdt:Transform=“InsertIfMissing”
和xdt:Locator=“Match(name)”
否则它将无法按您期望的方式工作(,)
因此,您的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="InsertIfMissing" xdt:Locator="Match(name)" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</configuration>
谢谢!我最终交换了HTTP模块的头。谢谢。我认为这是网站扩展带来的。可能需要小心使用xdt:Transform=“Insert”
,因为它可能会完全损坏您的web应用实例,因为每次计算它时,它都会尝试在您的applicationhost.config
中添加重复条目。使用xdt:Transform=“InsertIfMissing”
可能更安全。您还需要指定xdt:Locator=“Match(name)”
,否则xdt只匹配
元素名,这根本没有用!这个xdt:Locator=“Match(name)”对我有用…谢谢!