2

(我浏览了堆栈上的大量链接以及 Microsoft http://forums.iis.net/t/1161629.aspx/1 上的此类文章该解决方案根本不起作用。在标记为“重复”之前请记住这一点。我在询问之前做了功课)

我不确定这是否与 MVC4 有关,但这是我的规则:

<rewrite>
  <rules>
    <rule name="Apply Sub-Domain as Query String Argument" stopProcessing="false">
      <match url="^(.+)$" />
      <conditions trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="^(^local[a-z0-9]+)\.domain\.com(.*)$" />
      </conditions>
      <action type="Rewrite" url="https://local.domain.com{C:2}?cobrand={C:1}" logRewrittenUrl="false" />
    </rule>
  </rules>
</rewrite>

我希望这是一个将https://subdomain.domain.com其发送到 MVC4的 url,https://local.domain.com?cobrand=subdomain但它没有触发。

在我的 MVC 应用程序中,我有一个定义为:

<div>
    Cobrand = @HttpContext.Current.Request.QueryString["cobrand"]
</div>
<div>
    Requested URL = @HttpContext.Current.Request.Url
</div>
<div>
    Path = @HttpContext.Current.Request.Path
</div>

使用此请求的 url https://localdemo1.domain.com的以下输出:

<div>
    Cobrand = 
</div>
<div>
    Requested URL = https://localdemo1.domain.com
</div>
<div>
    Path = /
</div>

我想要的输出是:

<div>
    Cobrand = localdemo1
</div>
<div>
    Requested URL = https://local.domain.com?cobrand=localdemo1
</div>
<div>
    Path = /
</div>

关于站点设置的说明:

IIS 站点具有以下绑定:

HTTP::

local.domain.com

localdemo1.domain.com

localdemo2.domain.com

HTTPS::443(无主机配置,无法在 443 上配置主机,但已配置为允许 SSL)

PS:我在没有 HTTPS 的情况下尝试了这个,它产生了相同的结果,因为根本没有触发。

4

1 回答 1

1

这对我有用:

<rewrite>
  <rules>
    <rule name="Apply Sub-Domain as Query String Argument" stopProcessing="false">
      <match url="^.*$" />
      <conditions trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="^(^local[a-z0-9]+)\.domain\.com(.*)$" />
      </conditions>
      <action type="Redirect" url="https://local.domain.com{R:0}?cobrand={C:1}" />
    </rule>
  </rules>
</rewrite>

请注意,match urlas 已更改(接受空值)并且type="Redirect"已替换type="Rewrite".

{C:2}在这种情况下不起作用(我无法告诉你为什么......)但你可以使用它{R:0}

于 2013-01-24T02:21:16.873 回答