我404 Not Found
在Web.config
文件中使用httpErrors部分设置了自定义错误页面。
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" responseMode="ExecuteURL" path="/error/notfound"/>
</httpErrors>
导航到不存在的页面时,将获得以下URL:
http:// localhost / error / notfound?404; http:// localhost / ThisPageDoesNotExist /
我不想在URL中查询字符串,也不想301或302重定向到未找到的页面。我该如何实现?也许使用URL重写?
如果我理解正确,那么您想处理404 Not Found错误,而无需重新编写url,只需返回结果视图即可
实现此目的的一种方法是使用旧的,customErrors
但redirectMode="ResponseRewrite"
要确保原始URL不变。
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/NotFound" />
</customErrors>
另一种是将httpErrors
方法与existingResponse="Replace"
您目前使用它的方式完全相同
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear/>
<error statusCode="404" path="/Errors/NotFound.html" responseMode="ExecuteURL"/>
</httpErrors>
</system.webServer>
我试图重新您的问题,只有当我既有成功httpErrors
和customErrors
设置不 redirectMode="ResponseRewrite"
我的结论是:您可能customErrors
不使用ResponseRewrite
它而优先于httpErrors
处理程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句