【发布时间】:2014-08-12 18:41:09
【问题描述】:
在我的 ASP.NET SPA 应用程序中,我使用 web.config 设置重写规则,因此我可以刷新页面而不会出错(使用 Angularjs 时),但我也想在不存在页面时重定向到应用程序的主页手动输入网址,请告知我应该如何修改下面的代码以适应这个:
<rewrite>
<rules>
<rule name="Products" stopProcessing="true">
<match url="^products" />
<action type="Rewrite" url="/" />
</rule>
<rule name="Orders" stopProcessing="true">
<match url="^orders" />
<action type="Rewrite" url="/" />
</rule>
<rule name="Home" stopProcessing="true">
<match url="^home" />
<action type="Rewrite" url="/" />
</rule>
<rule name="List" stopProcessing="true">
<match url="^list" />
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
【问题讨论】:
-
Angular 路由和 asp.net "routing" 不应相互冲突,在这种情况下,您的所有服务器路由都应该重定向到根目录,从那以后,Angular 应该负责路由您的 SPA .我认为您应该添加一个重定向到您的索引的 404 错误页面,与 url 重写本身无关。
-
感谢您的回复,任何您可以参考的示例,对于这种情况。
-
是的,我要把它添加为答案
标签: asp.net angularjs url-rewriting