gpt4 book ai didi

angularjs - ASP.NET 5 中的 URL 重写

转载 作者:行者123 更新时间:2023-12-04 13:52:54 24 4
gpt4 key购买 nike

我正在使用 ASP.NET 5,其中更改了整个文件夹结构并替换了 web.config(与以前的 ASP.NET 版本相比)。我正在使用 angularJS 进行客户端路由,我有这条路线:

.when('/movies/add', {
templateUrl: '/Views/add.html',
controller: 'MoviesAddController'
})

只要我从 index.html 开始并单击指向/movies/add 的链接,一切都会正常工作。如果我使用/movies/add URL 重新加载页面,服务器会给我一个 404。根据本教程,我应该在 web.config 中进行重写,如下所示:
<!-- from http://stackoverflow.com/questions/25916851/wrapping-staticfilemiddleware-to-redirect-404-errors -->

<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<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" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

我正在使用 IIS Express 10.0(在 Windows 10 预览版中)。我知道 web.config 中的部分应该仍然存在于 ASP.NET 5 中以配置 IIS,但我没有得到任何结果。
我需要使用 IIS Express 做一些不同的事情吗? ASP.NET 5 中是否提供了另一种更通用的解决方案?

谢谢!

最佳答案

web.config仍受支持,但应进入 wwwroot文件夹。您可能缺少 IIS 的 Url Rewrite 模块。

或者,您可以编写自定义 OWIN 中间件来支持 html5 路由模式。

请参阅此示例:
http://geekswithblogs.net/shaunxu/archive/2014/06/10/host-angularjs-html5mode-in-asp.net-vnext.aspx

关于angularjs - ASP.NET 5 中的 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30945402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com