同一 ASP.NET 解决方案中的两个网站

Two websites in same ASP.NET solution

我在同一个 asp.net 解决方案中有两个网站(index.html 个文件)。我有两个域,我想定向到正确的 html 文件。

这是一个 angularjs 应用程序,所以我每个站点只有一个 html 文件。

我想要在 http://site1.myhostname.com/ 到 return /index.html.

对任何资源的所有请求

而且我希望所有对 http://site2.myhostname.com/ 到 return /site2/index 的任何资源的请求。html

配置 web.config and/or dns 配置是否可行?

我可以看到两个解决方案

  1. 第一个是在 IIS 中有 2 个不同的网站并使用适当的绑定配置。在这种情况下,每个网站都会有自己的文件夹和资源。

    这是我推荐的解决方案。

  2. 另一种解决方案是使用 IIS 的 URL 重写模块。

    你可以在那里安装它:http://www.iis.net/downloads/microsoft/url-rewrite

    然后在你的web.config

<system.webServer>
  <rewrite>
    <rules>        
      <rule name="Rewrite sub-domain to sub-directory" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
           <add input="{HTTP_HOST}" pattern="(\w+)\.company\.com" />
        </conditions>
        <action type="Rewrite" url="{C:1}/{R:0}" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

此规则会将来自子域的所有请求重写到子目录。