【问题标题】:MVC 6, .NET Core RC2 Rewrite to index.html on non /api urlsMVC 6,.NET Core RC2 在非 /api url 上重写为 index.html
【发布时间】:2016-10-13 11:51:43
【问题描述】:

我正在使用带有 .NET Core RC2 的 MVC 6

在我的 startup.cs 中(正如大多数人建议的那样):

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseDefaultFiles();
    app.UseStaticFiles();
    app.UseMvc();
}

在我的 wwwroot/web.config 文件中,我有:

<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
    <rewrite>
      <rules>
        <rule name="IndexHomeRule" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_URI}" matchType="Pattern" pattern="^/api/" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

我的目标是将所有非 /api url 重写为 index.html,以便 Angularjs 使用 html5mode 处理路由。主目录将加载 index.html,但除此之外,其他每个 url 都会出现 404 错误。如果不通过 web.config,如何设置重写?

我现在唯一的控制器是 api/BuyersController.cs,它使用 [Route("api/[controller]")] 路由

【问题讨论】:

    标签: angularjs asp.net-mvc asp.net-web-api web-config


    【解决方案1】:

    从 ASP.NET CORE RC2 到 RTM 的 URL 重写目前已被破坏,因为它存在于您的问题中。

    ASP.NET 团队目前正在开发一些中间件,作为解决此问题的直接 ASP.NET 解决方案。跟踪此问题的 github 问题位于下方。

    https://github.com/aspnet/BasicMiddleware/issues/43

    在这个其他问题线程中有一些解决方案可能在此期间对您有所帮助。

    https://github.com/aspnet/IISIntegration/issues/192

    【讨论】:

      猜你喜欢
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 2016-10-15
      • 2018-07-25
      • 2011-02-07
      • 1970-01-01
      相关资源
      最近更新 更多