global.asax: Application_Error how to get informations about the exception

J

John Holgerson

Hi, is it possible to get informations about the exception that
occured in that method??

(global.asax)
protected void Application_Error(Object sender, System.EventArgs e) {

}

thanks for help
John
 
R

Rajesh C K R

Yes..

You can write for ex,

protected void Application_Error(Object sender, System.EventArgs e)
{
System.Web.HttpContext context = HttpContext.Current;
System.Exception e= Context.Server.GetLastError();

LogError(e); //Your own logging function...

context.Server.ClearError();

Response.Redirect("some_error_occured_we_are_sorry.aspx");

}

Hope this helps



-Rajesh
http://www.sharpVoice.com
 
M

Mona

Hi John,

You can try the foolowing code snippet to do the same:

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>

<script language="C#" runat="server">
void Application_Error(object sender, EventArgs e)
{

Exception ex = Server.GetLastError().GetBaseException();

EventLog.WriteEntry("Test Web",
"MESSAGE: " + ex.Message +
"\nSOURCE: " + ex.Source +
"\nFORM: " + Request.Form.ToString() +
"\nQUERYSTRING: " + Request.QueryString.ToString() +
"\nTARGETSITE: " + ex.TargetSite +
"\nSTACKTRACE: " + ex.StackTrace,
EventLogEntryType.Error);


}
</script>

HTH

Mona[Grapecity]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top