ASP.NET重定向不存在的页面中使用重写规则在web.config中主页 [英] ASP.NET redirect non existing pages to homepage in web.config using rewrite rules
问题描述
在我使用的web.config设置重写规则我的ASP.NET应用程序的SPA,这样我就可以刷新页面没有错误(同时使用Angularjs),但我也想重定向到应用程序的主页,当不存在的页面手动输入网址,请指教我应该怎么修改低于code,以适应这样的:
<&改写GT;
<规则与GT;
<规则名称=产品stopProcessing =真>
<匹配URL =^产品/>
<作用TYPE =重写URL =//>
< /规则>
<规则名称=订单stopProcessing =真>
<匹配URL =^命令/>
<作用TYPE =重写URL =//>
< /规则>
<规则名称=家stopProcessing =真>
<匹配URL =^家/>
<作用TYPE =重写URL =//>
< /规则>
<规则名称=列表stopProcessing =真>
<匹配URL =^名单/>
<作用TYPE =重写URL =//>
< /规则>
< /规则>
< /重写>
您可以使用一个404错误处理重定向到您的主页(这里假设I'm Default.aspx的汇入作业,但将其更改为无论是你的家),在你的webconfig文件中写:
<结构> <&的System.Web GT;
<编译targetFramework =4.0/> <的customErrors模式=开redirectMode =ResponseRewrite>
<错误状态code =404重定向=Default.aspx的/>
< /&的customErrors GT;
< /system.web> < system.webServer>
< httpErrors errorMode =自定义>
<清除状态code =404/>
<错误状态code =404路径=/ Default.aspx的responseMode =ExecuteURL/>
< / httpErrors>
< /system.webServer>< /结构>
另外,你的角度配置使用以下重定向到家里:
$ routeProvider。
当('/',{'templateUrl':'a.html'})
。当('/ B',{'templateUrl':'b.html'})
不然的话({redirectTo:'/'})
}
希望有所帮助。
In my ASP.NET SPA application I am using web.config to set Rewrite Rules, so I can refresh pages without error (while using Angularjs), but I also would like to redirect to application's homepage, when non-existing page manually entered into url, please advise how should I modify code below to accommodate this:
<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>
You can use a 404 error handling to redirect to your homepage (here I´m assuming it´s Default.aspx, but change it to whatever is your home), on your webconfig file put:
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="Default.aspx" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/Default.aspx" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>
</configuration>
Also, on your angular configuration use the following to redirect to home:
$routeProvider.
when('/',{'templateUrl' : 'a.html'})
.when('/b',{'templateUrl' : 'b.html'})
.otherwise({redirectTo : '/'})
}
Hope that helps.
这篇关于ASP.NET重定向不存在的页面中使用重写规则在web.config中主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!