473,473 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

global.asax Application_Error not firing on forced exception??

I'm forcing an error/exception in one page as follows
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
Dim badthing As New Exception("XXX")
Throw badthing
End Sub

And attempting to set a session variable to that error in the
global.asax file as follows:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As Exception = Server.GetLastError()
Session("LASTERROR") = ex.Message.ToString +
ex.InnerException.Message.ToString + ex.Source.ToString
Session("xx") = "xx"
' Code that runs when an unhandled error occurs
End Sub

in my web.config I also have customerrors turned on and redirecting to
an errorpage.aspx page where I want to read that session variable:

The exception happens and I am taken to my errors page, but no sign of
the session variable. If I debug in VS.NET I notice it never makes it
to that subroutine in the global.asax file.
Am I missing something? Could it be that I have no application name?
Is this an IIS thing maybe?

Thanks for any help or information.
Nov 15 '07 #1
1 3649
re:
!The exception happens and I am taken to my errors page, but no sign of the session variable.
!Am I missing something?

You need to call Server.ClearError() after setting your session variables.

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As Exception = Server.GetLastError()
Session("LASTERROR") = ex.Message.ToString + ex.InnerException.Message.ToString + ex.Source.ToString
Session("xx") = "xx"
Server.ClearError()
End Sub


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"jobs" <jo**@webdos.comwrote in message news:07**********************************@c30g2000 hsa.googlegroups.com...
I'm forcing an error/exception in one page as follows
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
Dim badthing As New Exception("XXX")
Throw badthing
End Sub

And attempting to set a session variable to that error in the
global.asax file as follows:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As Exception = Server.GetLastError()
Session("LASTERROR") = ex.Message.ToString +
ex.InnerException.Message.ToString + ex.Source.ToString
Session("xx") = "xx"
' Code that runs when an unhandled error occurs
End Sub

in my web.config I also have customerrors turned on and redirecting to
an errorpage.aspx page where I want to read that session variable:

The exception happens and I am taken to my errors page, but no sign of
the session variable. If I debug in VS.NET I notice it never makes it
to that subroutine in the global.asax file.
Am I missing something? Could it be that I have no application name?
Is this an IIS thing maybe?

Thanks for any help or information.


Nov 15 '07 #2

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

Similar topics

3
by: JP | last post by:
I need to be able to trap errors at the application level. I added this code to the Global.asax file. The code I wrote is supposed to get the last error that was generated and write to the event...
5
by: vbMental | last post by:
I am deep into a project and cannot get this to work correctly. I am trying to make a custom error page that will be able to know what exception occurred. I already know about the defaultRedirect...
14
by: paul downing via DotNetMonster.com | last post by:
global file email send -------------------------------------------------------------------------------- guys, i'm developing an application and want to send an email with an error if it occurs...
7
by: Jonas | last post by:
Hi! I have an Application_Error method in global.asax that uses Server.Transfer to move execution to a custom error page. This works fine when an exception is thrown in one of the aspx or ascx...
2
by: tshad | last post by:
I have my error handling set up in Global.asax: Sub Application_Error(Sender As Object, E as EventArgs) In this procedure I call a function in a dll that will write out to a history file. ...
1
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are...
19
by: furiousmojo | last post by:
This is a strange problem. I have a project where the contents of global.asax application_error are not firing. It is an asp.net 2.0 application using web application projects. I have another...
1
by: paulo | last post by:
Hello, I have a DLL library containing some web services which are declared in each .asmx file in the following way: <%@ WebService Language="C#" Class="LibraryName.WebService" %> I would...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.