英文:
Umbraco application custom error redirect works for 500 status, but not for 404
问题
在我的Umbraco应用程序中,我已经创建了错误页面,并在web.config中定义了自定义错误重定向到该页面,以防发生故障,如下所示:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error" />
当应用程序返回状态码500时,它能够正常工作,但如果用户尝试访问不存在的页面,则重定向不会发生。我甚至尝试特别为404状态码定义重定向,如下所示:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error">
<error statusCode="404" redirect="~/Error" />
</customErrors>
但仍然没有成功。
英文:
In my umbraco application I have created error page and then defined in web.config custom error redirect to that page in case of failure like this:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error" />
It works fine in case application returns status 500, but if user wants to access not existing page then redirect does not happen. I even try to specifically define redirect for 404 status like this:
<customErrors mode="RemoteOnly" defaultRedirect="~/Error">
<error statusCode="404" redirect="~/Error" />
</customErrors>
but still without a success.
答案1
得分: 1
问题出现在umbracoSettings.config文件中。该文件的默认版本包含以下规则定义:
<errors>
<error404>1</error404>
</errors>
这似乎覆盖了在web.config中定义的规则,如果出现404状态,则重定向到ID为"1"的页面。删除包含error404的行后,一切都按预期工作:
<errors></errors>
英文:
The issue was in umbracoSettings.config. The default version of the file contained following rule definition:
<errors>
<error404>1</error404>
</errors>
It seemingly has overridden the rule defined in web.config and in case of 404 status redirected to page with id "1". Removing the line with error404 everything works as expected:
<errors></errors>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论