Active Server Pages Programming (ASP)/Global Error Handling
Expert: Srini Nagarajan - 5/9/2005
QuestionI would like to ask how do i do something like a global error handling function in ASP .NET . This function will be called everytime an error occurs in the script. I did a search on the web and found that there is actually this function called 'Application_Error' and have tried it out.
I'm trying to logged all errors that occurs on my webpage to a database to facilitate forensic debugging. Previously in ASP 2.0 , i can logged all the error information (eg. Line number, Source, Descriptions) into my ErrLog Database, but now i've found out that the errors in ASP .NET is very different. The errors (or they called it exceptions) they give is very different. Looks like those Object-Oriented kind of error message.
Is it possible for .NET to have the same kind of error logging function like ASP 2.0 (eg giving me the line at which the error occurred) ?
Or if possible , can you explain to me how to debug the error messages in .NET ?
Let me know if you don't understand my questions.
Thanks!
AnswerHi
Sorry for the delay in reply...
Here is the simple code sample stores the error into a text file... you can modify and store into the db
in .net you have better control on error handling.. You can set in your web.config to handle the error or as you said application_error in global.asax
In this sample it talks how to store into a text file.
http://www.codeproject.com/aspnet/createlogfiles.asp
Here is the most advanced version of error handling..
http://www.codeproject.com/csharp/NotSoSimpleErrorLog.asp
Happy programming!
-Srini