为 IIS 子应用程序配置不同的主机名
Configuring different hostnames for IIS sub-aplications
我在 IIS 上的 DefaultWebSite 下有几个应用程序指向相同的源代码并通过别名区分:
localhost/app1
localhost/app2
localhost/app3
是否可以通过 windows hosts 文件为每个应用配置不同的主机名?例如,让它们像这样:
app1.localhost
app2.localhost
app3.localhost
我需要它来测试单点登录功能并确保身份验证 cookie 不会在同一域 (localhost) 内共享
在我看来,你应该修改hosts文件和url重写规则来达到你的要求。
首先,您应该转到主机文件 (C:\Windows\System32\drivers\etc) 并添加以下设置。
127.0.0.1 app1.localhost
127.0.0.1 app2.localhost
127.0.0.1 app3.localhost
然后你可以在 web.config 中添加以下 url 重写规则,将 appx.localhost 重写为 localhost/app1。
<rule name="cio">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*).localhost" />
</conditions>
<action type="Rewrite" url="http://localhost/{C:1}/{R:0}" />
</rule>
我在 IIS 上的 DefaultWebSite 下有几个应用程序指向相同的源代码并通过别名区分:
localhost/app1
localhost/app2
localhost/app3
是否可以通过 windows hosts 文件为每个应用配置不同的主机名?例如,让它们像这样:
app1.localhost
app2.localhost
app3.localhost
我需要它来测试单点登录功能并确保身份验证 cookie 不会在同一域 (localhost) 内共享
在我看来,你应该修改hosts文件和url重写规则来达到你的要求。
首先,您应该转到主机文件 (C:\Windows\System32\drivers\etc) 并添加以下设置。
127.0.0.1 app1.localhost
127.0.0.1 app2.localhost
127.0.0.1 app3.localhost
然后你可以在 web.config 中添加以下 url 重写规则,将 appx.localhost 重写为 localhost/app1。
<rule name="cio">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*).localhost" />
</conditions>
<action type="Rewrite" url="http://localhost/{C:1}/{R:0}" />
</rule>