我在IIS上托管了一个ASP.NET网站。 我在某些页面上使用了“应用程序请求路由”代理和url重写规则。
我将重写规则添加到从http://example.com/my-url/到http://other-server/my-url/的代理请求中。
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^my-url/.*" />
<action type="Rewrite" url="http://other-server/{R:0}" />
</rule>
问题是我想实现一种条件,该条件不是针对所有用户而是仅针对10%或其他部分用户重写此页面。
对于每个用户,打开页面的结果应该相同。
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^my-url/.*" />
<conditions>
<add input="Is it possible to write a rule that works only for 10% users?" />
</conditions>
<action type="Rewrite" url="http://other-server/{R:0}" />
</rule>
有可能吗?
答案 0 :(得分:0)
根据您的描述,我建议您可以尝试在代码中编写hte逻辑,以将一些特殊数据存储在http cookie中,例如“ role = roleA”,然后您可以尝试编写符合httpcookie的url重写角色条件。
像下面这样:
GET http://aaaaaaa.com/test.aspx HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-US
User-Agent: Mozilla/5.0
Host: myserver.com
Cookie: role=roleA
网址重写规则:
<rule name="Reverse Proxy" stopProcessing="true">
<match url="^my-url/.*" />
<conditions>
<add input="{HTTP_COOKIE}" pattern="rule=ruleA" />
</conditions>
<action type="Rewrite" url="http://other-server/{R:0}" />
</rule>