ASP.net Custom Error Page

im trying to implement a custom error page, what I want to do is create a single common error page that can display the error that occurred or other information (custom error message). if an error occurs on the website, the user should be directed to this page on which the error message is displayed.

so, for example, if I had a page that tried to update something in the database, but something went wrong, I should be redirected to the page with an error that would have some kind of custom text, for example, that- something like "an error occurred with bla bla bla ... contact the administrator."

hope it makes sense

thank

+3
source share
3 answers

In your webconfig you can specify a customErrors element:

<system.web>
   <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" />
</system.web>

DefaultRedirect should be the path to your error page. This is useful to indicate when common errors occur, but will not allow you to access the stack trace. Otherwise, you want to handle this in gloabal.asax in Application_Error and then redirect to the error page using a special message.

+2
source

You can use the Application_Error event handler in the global.asax.cs (or global.asax.vb) file to determine what happens when the user encounters an error.

. , .

+2

Application_Error global.asax, . , , ...

Application_Error , .

ASP.NET

+2

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


All Articles