Umbraco应用程序自定义错误重定向对500状态有效,但对404状态无效。

huangapple go评论86阅读模式
英文:

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:

&lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;~/Error&quot; /&gt;

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:

&lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;~/Error&quot;&gt;
  &lt;error statusCode=&quot;404&quot; redirect=&quot;~/Error&quot; /&gt;
&lt;/customErrors&gt;

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:

&lt;errors&gt;
  &lt;error404&gt;1&lt;/error404&gt;
&lt;/errors&gt;

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:

&lt;errors&gt;&lt;/errors&gt;

huangapple
  • 本文由 发表于 2020年1月3日 15:16:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定