Add the web.config key to always redirect when you receive unhandled exceptions

I once saw that it was possible to do something like adding a key in the web.config file to redirect to the default error page every time an unhandled exception was found.

Is it possible? as?

+3
source share
3 answers

Add the CustomErrors section to your web.config.

<customErrors defaultRedirect="ErrorPage.aspx" mode="RemoteOnly" />
+5
source

Yes section customErrorsin web.config file.

<customErrors defaultRedirect="~/GenericError.aspx" mode="On" />

This will redirect your users to that defaultRedirect(URL) when they encounter an error.

, , HTTP

<customErrors defaultRedirect="~/GenericError.aspx" mode="On">
    <error statusCode="500" redirect="~/Error.aspx"/>
    <error statusCode="404" redirect="~/NotFound.aspx"/>
</customErrors>

.

+6
<customErrors defaultRedirect="~/serverErrorPage.aspx" mode="On" redirectMode="ResponseRewrite"/>

It is not suitable for real use before the .NET3.5 Service Pack 1, since there was no redirectMode attribute before, and it will always act with the default value "ResponseRedirect", which will redirect to the error page instead of direct display; therefore, instead of responding to an error, it is "successfully" redirected to another page, and then returns an error!

0
source

Source: https://habr.com/ru/post/1769809/


All Articles