2

I have set a server variable to be available on my IIS server called COUNTRY_PATH

I am doing a Reverse Proxy rewrite from one site to another and need to access this server variable in my proxied site. However it never seems to have a value.

<rule name="Country Codes For DotCom" stopProcessing="true">
    <match url="^([A-Z]{2,2})(/)(microsite)(.*)" />
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
          <add input="{HTTP_HOST}" pattern="\.com$" />
     </conditions>
     <serverVariables>
          <set name="COUNTRY_PATH" value="{R:1}{R:2}{R:3}" />
     </serverVariables>
     <action type="Rewrite" url="http://internal.example.com/{R:1}{R:2}{R:3}{R:4}" />
</rule>

Are Server Variables available for reverse proxy?

I am using the following code to get the server variable:

string countryPath = HttpContext.Current.Request.ServerVariables["COUNTRY_PATH"]

Can anyone suggest what I am doing wrong?

4

1 回答 1

1

当您将服务器变量添加到允许的服务器变量以及在重写 serverVariable 元素中引用它时,您需要在服务器变量前面加上“HTTP_”。确认您已正确执行此操作的一种简单方法是使用内置的类型向下功能,输入 {H 然后从可用选项中选择 {HTTP_COUNTRY_PATH}。

有关完整说明,请阅读以下文章的以下部分:使用入站重写规则设置请求标头和服务器变量

http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-20-configuration-reference

于 2014-07-29T09:56:45.243 回答