【问题标题】:URL Rewrite redirection based on PostAuthenticate results基于 Post Authenticate 结果的 URL 重写重定向
【发布时间】:2016-12-09 15:51:25
【问题描述】:

使用 Url Rewrite 模块,我想根据在自定义身份验证过程中检索到的某些值来驱动重写。

在 PostAuthenticateRequest 期间,我尝试使用HttpContext.Current.Request.Headers.Add("name", "value"); 设置 HTTP 标头,该标头在离开 HTTPModule 之前在请求对象上可见。

但是在 URL 重写中,一个非常基本的条件失败了,因为 HTTP_name 下没有文本。

<rule name="customrule" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_name}" pattern=".+" /> <!-- doesn't work -->
    <!-- <add input="{HTTP_name}" pattern=".*" /> works -->
  </conditions>
  <action type="Rewrite" url="https://someotherdomain/{R:0}" />
</rule>

将条件上的模式更改为 .* 让规则通过,但 URL 显示为 https:///{R:0}。如果我手动添加name Header before 从服务器请求资源它能够找到数据。不幸的是,在提出请求之前,我没有数据。

我可以跨 IIS 模块使用标头吗?如何从 PostAuthenticate 获取值到 URL Rewrite?

【问题讨论】:

    标签: c# iis url-rewriting iis-7.5 arr


    【解决方案1】:

    根据此博客http://blogs.iis.net/wonyoo/relationship-between-application-request-routing-and-url-rewrite-modules,ARR 实现发生在 URL 重写之后的某个时间点,并且是外部服务器的实际代理。

    据我了解,Url Rewrite 模块会在请求管道的早期提取标头。因此,Url Rewrite 模块无法访问标题。管道继续通过 Authentication 和 PostAuthentication 执行,并最终将作为代理的职责移交给 Application Request Routing。

    【讨论】:

      猜你喜欢
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      相关资源
      最近更新 更多