【问题标题】:Setting root in .NET MVC4 project to /app/index.html将 .NET MVC4 项目中的根设置为 /app/index.html
【发布时间】:2013-10-14 20:01:00
【问题描述】:

我正在使用 MVC4 项目,但我将使用 angularjs 作为前端,并使用 WebApi 来提供 JSON。

我现在遇到的问题是我无法弄清楚如何配置我的网站以将 /app/index.html 视为项目的根目录。

我确定它在 web.config 中的某些内容,但无法弄清楚如何强制 ISS 将其设置为默认值。我仍然需要能够访问 /Api/ 以进行我的 api 调用。

谢谢你。

【问题讨论】:

  • 如果您不打算使用 ASP.NET MVC,是否需要完整的 MVC 项目?如果您有一个包含 Web 项目和 API 项目的解决方案,那么您的 Web 项目应该能够只是一个文件夹结构,设置 Angular 喜欢它的方式。您将不需要 MVC 路由引擎等...
  • 这是一个选项,如果我能弄清楚如何让 Web 项目指向 /app 文件夹而不是 /Controllers 文件夹。

标签: .net asp.net-mvc-4 iis


【解决方案1】:

在您的 web.config 中使用重写规则:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Default" stopProcessing="true">
        <match url="^(?!api|images|Content|Views|Scripts|favicon|robots).*" />
        <action type="Rewrite" url="index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

【讨论】:

    猜你喜欢
    • 2012-08-10
    • 1970-01-01
    • 2013-03-24
    • 2011-08-22
    • 2021-05-23
    • 2013-08-16
    • 1970-01-01
    • 2018-10-03
    • 2018-07-05
    相关资源
    最近更新 更多