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 开发者_StackOverflow中文版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
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.
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.
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
精彩评论