iis-7 - 使用 IIS7 的 URL 重写捕获 Cookie 中的值

标签 iis-7 url-rewriting

我需要为我的 IIS 7.5 网站编写一个 URL 重写规则,捕获特定 cookie 中的值,然后使用该值构建 URL。例如,传入的请求如下所示:

GET http://myserver.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: foo=bar; bat=bar

我想将它们路由到此(基于“foo”cookie 值):

http://myserver.com/bar/test.aspx

查看文档并搜索示例后,我被难住了!感谢您的帮助。

最佳答案

回答我自己的问题,这是一个有效的示例。该模式可能需要额外的工作,具体取决于需要支持的字符,但以下规则将使用发现的 cookie 值并路由到发现的服务器,并且可以通过 IPv4 地址或名称(字母数字和句点)指定服务器)。

<rule name="Route Base On Cookie" stopProcessing="true">
  <match url="^(.*)" />
    <conditions>
       <add input="{HTTP_COOKIE}" pattern="foo=(.*?);" />
    </conditions>
  <action type="Rewrite" url="http://{C:1}/{R:0}" />
</rule>

关于iis-7 - 使用 IIS7 的 URL 重写捕获 Cookie 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8763967/

相关文章:

wcf - TCP 错误代码 10013 netTcpBinding 服务和 Silverlight 客户端的跨域策略错误

security - 将证书 .pem 转换为 .der/.cer

mod-rewrite - 使用 mod_rewrite 重写基本 URL 并为其添加特定单词

azure - 如何通过IP地址阻止对子域的访问

.htaccess - 如何写入 htaccess 文件

c# - ASP.NET 网站似乎定期(每小时)卡住/停止/暂停/挂起

c# - 用户驱动的 session 过期

asp.net - 我的 IIS7 URL 重写规则不断消失

url-rewriting - 如何允许 WordPress 和 Laravel 通过 htaccess 共享顶级 URL

.htaccess - 别名和 mod_rewrite