我有一个用ASP.NET MVC 5编写的Web应用程序,其中包含有关其用户的信息。现在我想为每个可以作为我的网站的子域访问的用户创建一个配置文件页面(例如user1.example.com
,user2.example.com
,...)。ASP.NET MVC中的子域路由的IIS URL重写规则5
我希望这些子域可以通过HTTP访问,而其他应用程序必须使用HTTPS。
我在IIS上运行Web应用程序,所以我想如果我使用URL重写规则将user1.example.com
重写为example.com/Profile/Index?name=user1
,那么Web应用程序本身不必知道正在使用的子域。我想出了这些重写规则:
<rewrite>
<rules>
<clear />
<rule name="Rewrite user subdomains into query string" stopProcessing="true">
<match url="^(.+)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
<add input="{HTTP_HOST}" pattern="^([^.]+)\.example\.com$" />
</conditions>
<action type="Rewrite" url="/Profile/Index?name={C:1}" />
</rule>
<rule name="Redirect to https without www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
此代码遗憾的是不甚至超过user1.example.com
改写user1.example.com
到example.com/Profile/Index?name=user1
和力量HTTPS。
有人请向我解释为什么以及如何解决这个问题?