473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Catching the error in global.asax file

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


--


Aug 18 '06 #1
1 1893
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


--


Aug 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pa Ji | last post by:
I just created a simple web application and tried to run it. Getting following...any idea what I'm missing Thanks in advance...
2
by: Daniel Rimmelzwaan | last post by:
I receive the error below when I try to access my aspx page in a browser. I created the aspx page on my laptop (but the solution resides on a server) with VS.NET and it builds correctly on the...
14
by: Roland Hall | last post by:
Since I'm not getting any response from the community, I'm reposting this under my managed account. I've turned my web.config friendly error messages off and it may be easier to view what I'm...
1
by: Neil | last post by:
Hello - In every project I try to compile and run, I'm getting a parser error on global.asax (pasted below). I have rebuilt and recompiled, and this happens on every project on my machine, no...
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
1
by: =?Utf-8?B?QWNl?= | last post by:
hello, i just converted old .net project (it was a solution with web project and class project) built in .net 1.0 and 1.1 framework to .net 2.0. as i expected, when i clicked on the solution file...
25
by: JJ | last post by:
I only want to catch 404 errors at the application level (the rest are will be handled by the customerrors section of the web.config). How do I check for the error code in the Application_Error...
2
by: DamienS | last post by:
Hi, I'm trying to get away from using global.asax for reasons of 'neatness'. Am I able to register a HTTPModule that captures the starting of a user session? Isn't Session_Start an event in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.