3

im trying to implement a custom error page, what i want to be able to do is have a single generic error page which can display the error which occurred or other information (custom error message). when a error occurs on the website, the user should be directed to this page which shows the error message.

so for example if i had a page which was trying to update something to a database, but something went wrong, i should be redirected to the error page which will have some custom text like something like " there has been an error with bla bla bla ... please contact administrator".

hope this makes sense

thanks

3 Answers 3

2

In your webconfig you could specify the customErrors element:

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

The defaultRedirect should be the path to your Error page. This is good to specify when general errors occur, but it won't let you access the stack trace. Otherwise you want to handle that in the gloabal.asax in the Application_Error and then redirect to the error page with the custom message.

Sign up to request clarification or add additional context in comments.

1 Comment

It's generally worth having a static error page (e.g. Error.htm), because an exception could be thrown while processing a request for a dynamic page Error.aspx.
2

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

I've used this before. You can get the exception, send the admin an email, and display a message to the user, or log the error to the database.

Comments

2

You handle that in the Application_Error section of the global.asax file that you would need to add to your project for the application. I could go into detail but this link already should provide enough information to get you going...

Try looking at the How to use the Application_Error method section of this page, that should give you a good start.

Custom Error Handling in ASP.NET

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.