PC Review


Reply
Thread Tools Rate Thread

Catching the error in global.asax file

 
 
Groove
Guest
Posts: n/a
 
      18th Aug 2006
Hey guys - I'm sure this is a commonly asked question but here goes.

I'm trying to catch the error in my global.asax file and redirect to a error
page which will email me the actual error upon page load. Everything seems
to work OK except catch the actual error. It detects the error when I break
the connection string to MS SQL or pause the db itself. The error page is
displayed and I get the email. Only problem is that my session variable
always contains nothing. My code is straight from Murach's ASP.NET 2.0 book
so it makes me think that my issue is environmental.

Any ideas?? Thanks!

My global.asax:

Sub Application_Error(ByVal Sender As Object, ByVal E As EventArgs)


Dim excException As Exception


excException = Server.GetLastError.InnerException

Session("ApplicationError") = excException

Response.Redirect(Application("ApplicationPath") & "errors/500.aspx")


End Sub





My error page:



Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

If Page.IsPostBack = False Then

SendEmail(Session("ApplicationError"))

End If

End Sub





Protected Sub SendEmail(ByVal strError As String)



Dim objMail As New MailMessage

Dim strHTML As String

strHTML = ..etc..... & stError &...etc...

objMail.From = "x"

objMail.To = "y"

objMail.Subject = "....ERROR"

objMail.BodyFormat = MailFormat.Html

objMail.Body = strHTML

SmtpMail.SmtpServer = "z"

SmtpMail.Send(objMail)

End Sub




--




 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      18th Aug 2006
Groove,
What I would do here instead of going around in circles, is make the email
method call avaiable right in Global, and call the email method right
after the

excException = Server.GetLastError.InnerException

line. Then you don't need to worry about session state, and the redirect
becomes a non-issue.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"Groove" wrote:

> Hey guys - I'm sure this is a commonly asked question but here goes.
>
> I'm trying to catch the error in my global.asax file and redirect to a error
> page which will email me the actual error upon page load. Everything seems
> to work OK except catch the actual error. It detects the error when I break
> the connection string to MS SQL or pause the db itself. The error page is
> displayed and I get the email. Only problem is that my session variable
> always contains nothing. My code is straight from Murach's ASP.NET 2.0 book
> so it makes me think that my issue is environmental.
>
> Any ideas?? Thanks!
>
> My global.asax:
>
> Sub Application_Error(ByVal Sender As Object, ByVal E As EventArgs)
>
>
> Dim excException As Exception
>
>
> excException = Server.GetLastError.InnerException
>
> Session("ApplicationError") = excException
>
> Response.Redirect(Application("ApplicationPath") & "errors/500.aspx")
>
>
> End Sub
>
>
>
>
>
> My error page:
>
>
>
> Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
>
> If Page.IsPostBack = False Then
>
> SendEmail(Session("ApplicationError"))
>
> End If
>
> End Sub
>
>
>
>
>
> Protected Sub SendEmail(ByVal strError As String)
>
>
>
> Dim objMail As New MailMessage
>
> Dim strHTML As String
>
> strHTML = ..etc..... & stError &...etc...
>
> objMail.From = "x"
>
> objMail.To = "y"
>
> objMail.Subject = "....ERROR"
>
> objMail.BodyFormat = MailFormat.Html
>
> objMail.Body = strHTML
>
> SmtpMail.SmtpServer = "z"
>
> SmtpMail.Send(objMail)
>
> End Sub
>
>
>
>
> --
>
>
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Global.asax file paul downing via DotNetMonster.com Microsoft ASP .NET 14 20th Dec 2004 09:11 AM
Global.asax error Philip Townsend Microsoft ASP .NET 0 8th Mar 2004 04:05 PM
Global.asax file Prince Microsoft ASP .NET 6 2nd Dec 2003 06:57 AM
Global Error handling in Applicatio_Error() of Global.asax VSK Microsoft ASP .NET 1 29th Jul 2003 04:12 AM
Re: Global ASAX error David Banister Microsoft ASP .NET 0 15th Jul 2003 06:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.