如何在ASP.NET Core RC2中完成URL重写?当我刷新页面时,从RC1迁移到RC2破坏了我的Angular 2路由。
之前,我在wwwroot中的web.config中使用了这样的规则。使用RC2,我什至不确定我的wwwroot中是否应该有一个web.config,还是我的项目基础中只有一个。
这是我的基本web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="true" stdoutLogEnabled="true" />
</system.webServer>
</configuration>
这是我的wwwroot web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!--Redirect selected traffic to index -->
<rule name="Index Rule" 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" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="^/account/" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
当我刷新角度2路由时,我Status Code: 404; Not Found
从ASP.NET获得了一个
我发现史蒂夫·桑德森(Steve Sanderson)的解决方案似乎有效。他为RouteBuilder写了扩展名。您可以通过调用扩展方法MapSpaFallbackRoute在Setup.cs中对其进行配置
https://github.com/aspnet/JavaScriptServices
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句