【发布时间】: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