【问题标题】:Two websites in same ASP.NET solution同一个 ASP.NET 解决方案中的两个网站
【发布时间】:2015-05-26 13:45:42
【问题描述】:

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

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

我希望对http://site1.myhostname.com/ 的任何资源的所有请求都返回/index.html。

我希望所有对http://site2.myhostname.com/ 资源的请求都返回/site2/index.html

这可以通过配置 web.config 和/或 dns 配置来实现吗?

【问题讨论】:

  • 假设我理解 - “解决方案”不一定等同于“IIS 网站/应用程序”。您可以将每个“文件夹”标记为它自己的 IIS“网站/应用程序”,每个都有自己的 host header(然后在 DNS 中处理)。

标签: asp.net angularjs iis url-rewriting


【解决方案1】:

我可以看到两个解决方案

  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>

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

【讨论】:

  • 在看到这个答案之前,我提出了使用 iis 重写模块的第二个建议。该模块已在 web.config 中用于将所有请求重定向到 index.html 页面(单页 angularjs 应用程序)。我为第二个站点添加了另一个规则,并使用 HTTP_HOST 条件将请求重写为正确的 index.html
猜你喜欢
  • 2013-04-12
  • 2023-04-05
  • 1970-01-01
  • 2015-08-02
  • 2010-11-19
  • 1970-01-01
  • 1970-01-01
  • 2010-12-19
  • 1970-01-01
相关资源
最近更新 更多