我正在尝试在具有2个条件的UrlRewrite中配置一条规则:
I'm trying to configure a rule in UrlRewrite that has 2 conditions:
- HTTP标头 HTTP_HOST 需要匹配某个域(api.contoso)
- HTTP请求中必须存在一个自定义HTTP标头 x-app-version
- HTTP header HTTP_HOST needs to match a certain domain (api.contoso)
- A custom HTTP header x-app-version needs to be present in the HTTP request
根据此信息,我想在后端重定向到该API的其他版本.
based on this info, I'd like to redirect to a different version of the API in the back-end.
问题该规则在第一个条件下表现正常.当 HTTP_HOST 与api.contoso匹配时,它将启动.但是,它会忽略我的自定义 x-app-version 标头.
Problem The rule is behaving as expected on the first condition. It kicks in when HTTP_HOST matches api.contoso. However, it ignores my custom x-app-version header.
假设因此,我担心只能与下拉列表中有限的预定义HTTP标头集( HTTP_HOST , REMOTE_ADDRESS , REMOTE_HOST ,…)
Assumption So, I fear that a UrlRewrite condition only can be defined in combination with the limited set of predefined HTTP headers from the dropdown (HTTP_HOST, REMOTE_ADDRESS, REMOTE_HOST, …)
问题假设是正确的还是应该可行?我的配置或其他方法是否存在基于自定义定义的HTTP标头的条件的错误?
Question Is assumption correct or should this be possible whatsoever? Is there a mistake in my config or other approach to have conditions based on a custom defined HTTP header?
<rule name="ARR_test2" enabled="false"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="api.contoso" /> <add input="{x-app-version}" pattern="1" /> </conditions> <action type="Rewrite" url="FARM_apiv1/{R:0}" /> </rule> 推荐答案好,我发现了如何在UrlRewrite条件下使用自定义HTTP标头:
Ok, I found out how to use custom HTTP headers in a UrlRewrite condition:
- 自定义标头必须以"HTTP_"开头.
- 用下划线代替破折号
例如:为了检索自定义标头"x-app-version",我可以使用"HTTP_x_app_version".所以我的UrlRewrite配置应该像这样
E.g.: in order to retrieve my custom header "x-app-version", I can use "HTTP_x_app_version". So my UrlRewrite config should look like this
<rule name="ARR_test2" enabled="false"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="api.contoso" /> <add input="{HTTP_x_app_version}" pattern="1" /> </conditions> <action type="Rewrite" url="FARM_apiv1/{R:0}" /> </rule>在文档中实际上已经很清楚地提到了它: msdn.microsoft/zh-us/library/ms524602(v = vs.90).aspx
It's actually mentioned quite clear in the documentation: msdn.microsoft/en-us/library/ms524602(v=vs.90).aspx
更多推荐
基于自定义HTTP标头的UrlRewrite条件
发布评论