Application_Error in Global.asax

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

I have an ASP.NET application developed in Visual Studio .NET 2003.

The Application_Error in Global.asax never gains control. If the following
is in Global.asax and I cause a Divide-by-zero the message never appears.

protected void Application_Error( Object sender, EventArgs e )
{
Response.Write("Error" );
Server.ClearError( );
}

What am I overlooking?
 
Thanks but that didn't help.

I am hoping someone who uses the Global.asax will point out the obvious
thing I am overlooking.
 
Typically, the error is not in the global asax file but in the page. You
most likely have hooked up your error event at the page level (I believe vb
does that by default, not sure). Have a look at your initializateComponent
routine. Look for this line Page.Error += ....
This prevents run-time errors from percolating up the stack to the global
level. In effect, exceptions are swallowed at the page level if they aren't
caught. You can choose to remove it or transfer your code in global asax to
the page level error event handler.
 
Hi,

In C# ASP.NET Web Application project error handling is not done at page
level by default. The problem can be that by default several handlers are
exposed in Global asax.cs but they are NOT assigned to events. If error
handling is supposed to be at the HttpApplication level access property
editor for Global.asax.cs[Design] select events tab and assign a proper
handler to the Error event. This can be also done manually in
InitializeComponent().

regards,
Marek

Alvin Bruney said:
Typically, the error is not in the global asax file but in the page. You
most likely have hooked up your error event at the page level (I believe vb
does that by default, not sure). Have a look at your initializateComponent
routine. Look for this line Page.Error += ....
This prevents run-time errors from percolating up the stack to the global
level. In effect, exceptions are swallowed at the page level if they aren't
caught. You can choose to remove it or transfer your code in global asax to
the page level error event handler.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thom Little said:
I have an ASP.NET application developed in Visual Studio .NET 2003.

The Application_Error in Global.asax never gains control. If the
following
is in Global.asax and I cause a Divide-by-zero the message never appears.

protected void Application_Error( Object sender, EventArgs e )
{
Response.Write("Error" );
Server.ClearError( );
}

What am I overlooking?
 
I created a new C# project. I added a button. The button issues a throw
....

throw new Exception("AAAAAAAA" );

Global.asax contains one change ...

protected void Application_Error(Object sender, EventArgs e)
{
Response.Write("Application_Error" );
}

When I run the application and click the button I get the default error
excepting message page.

I can find no way to manipulate any event properties in Global.asax using
the Designer.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Marek said:
Hi,

In C# ASP.NET Web Application project error handling is not done at page
level by default. The problem can be that by default several handlers are
exposed in Global asax.cs but they are NOT assigned to events. If error
handling is supposed to be at the HttpApplication level access property
editor for Global.asax.cs[Design] select events tab and assign a proper
handler to the Error event. This can be also done manually in
InitializeComponent().

regards,
Marek

Alvin Bruney said:
Typically, the error is not in the global asax file but in the page. You
most likely have hooked up your error event at the page level (I believe vb
does that by default, not sure). Have a look at your initializateComponent
routine. Look for this line Page.Error += ....
This prevents run-time errors from percolating up the stack to the global
level. In effect, exceptions are swallowed at the page level if they aren't
caught. You can choose to remove it or transfer your code in global asax to
the page level error event handler.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Thom Little said:
I have an ASP.NET application developed in Visual Studio .NET 2003.

The Application_Error in Global.asax never gains control. If the
following
is in Global.asax and I cause a Divide-by-zero the message never appears.

protected void Application_Error( Object sender, EventArgs e )
{
Response.Write("Error" );
Server.ClearError( );
}

What am I overlooking?
 
Hi Thom,

I am not sure if this is the real problem you're facing but try the
folowing:
When editing Global.asax.cs press shift-F7. You should get
Global.asax.cs[Design] designer. Then access property editor and assign
Application_Error handler to Error event.

Marek

Thom Little said:
I created a new C# project. I added a button. The button issues a throw
...

throw new Exception("AAAAAAAA" );

Global.asax contains one change ...

protected void Application_Error(Object sender, EventArgs e)
{
Response.Write("Application_Error" );
}

When I run the application and click the button I get the default error
excepting message page.

I can find no way to manipulate any event properties in Global.asax using
the Designer.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Marek said:
Hi,

In C# ASP.NET Web Application project error handling is not done at page
level by default. The problem can be that by default several handlers are
exposed in Global asax.cs but they are NOT assigned to events. If error
handling is supposed to be at the HttpApplication level access property
editor for Global.asax.cs[Design] select events tab and assign a proper
handler to the Error event. This can be also done manually in
InitializeComponent().

regards,
Marek

Alvin Bruney said:
Typically, the error is not in the global asax file but in the page. You
most likely have hooked up your error event at the page level (I
believe
vb
does that by default, not sure). Have a look at your initializateComponent
routine. Look for this line Page.Error += ....
This prevents run-time errors from percolating up the stack to the global
level. In effect, exceptions are swallowed at the page level if they aren't
caught. You can choose to remove it or transfer your code in global
asax
to
the page level error event handler.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
I have an ASP.NET application developed in Visual Studio .NET 2003.

The Application_Error in Global.asax never gains control. If the
following
is in Global.asax and I cause a Divide-by-zero the message never appears.

protected void Application_Error( Object sender, EventArgs e )
{
Response.Write("Error" );
Server.ClearError( );
}

What am I overlooking?
 
If you don't want the default error page to show up you need to clean up
those execution errors. Just add Context.ClearError() call to the error
handler. And the error handle has to be named Application_OnError.

Jerry

Thom Little said:
I created a new C# project. I added a button. The button issues a throw
...

throw new Exception("AAAAAAAA" );

Global.asax contains one change ...

protected void Application_Error(Object sender, EventArgs e)
{
Response.Write("Application_Error" );
}

When I run the application and click the button I get the default error
excepting message page.

I can find no way to manipulate any event properties in Global.asax using
the Designer.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Marek said:
Hi,

In C# ASP.NET Web Application project error handling is not done at page
level by default. The problem can be that by default several handlers are
exposed in Global asax.cs but they are NOT assigned to events. If error
handling is supposed to be at the HttpApplication level access property
editor for Global.asax.cs[Design] select events tab and assign a proper
handler to the Error event. This can be also done manually in
InitializeComponent().

regards,
Marek

Alvin Bruney said:
Typically, the error is not in the global asax file but in the page. You
most likely have hooked up your error event at the page level (I
believe
vb
does that by default, not sure). Have a look at your initializateComponent
routine. Look for this line Page.Error += ....
This prevents run-time errors from percolating up the stack to the global
level. In effect, exceptions are swallowed at the page level if they aren't
caught. You can choose to remove it or transfer your code in global
asax
to
the page level error event handler.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
I have an ASP.NET application developed in Visual Studio .NET 2003.

The Application_Error in Global.asax never gains control. If the
following
is in Global.asax and I cause a Divide-by-zero the message never appears.

protected void Application_Error( Object sender, EventArgs e )
{
Response.Write("Error" );
Server.ClearError( );
}

What am I overlooking?
 
But ... the light is so much better over here ...

Thanks. That was the problem. I was putting out the message and then it
was getting overlaid by the default error page.

When I added Context.ClearError() in the Application_Error the default page
stopped overlaying my message.

Thank you both for the help.

BTW I am using Visual Studio .NET 2003 and can find no way to access event
assignments from the designer. I did nothing special to make an assignment
and the Application_Error gained control as it should.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Marek said:
Hi Thom,

I am not sure if this is the real problem you're facing but try the
folowing:
When editing Global.asax.cs press shift-F7. You should get
Global.asax.cs[Design] designer. Then access property editor and assign
Application_Error handler to Error event.

Marek

Thom Little said:
I created a new C# project. I added a button. The button issues a throw
...

throw new Exception("AAAAAAAA" );

Global.asax contains one change ...

protected void Application_Error(Object sender, EventArgs e)
{
Response.Write("Application_Error" );
}

When I run the application and click the button I get the default error
excepting message page.

I can find no way to manipulate any event properties in Global.asax using
the Designer.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Marek said:
Hi,

In C# ASP.NET Web Application project error handling is not done at page
level by default. The problem can be that by default several handlers are
exposed in Global asax.cs but they are NOT assigned to events. If error
handling is supposed to be at the HttpApplication level access property
editor for Global.asax.cs[Design] select events tab and assign a proper
handler to the Error event. This can be also done manually in
InitializeComponent().

regards,
Marek

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
Typically, the error is not in the global asax file but in the page. You
most likely have hooked up your error event at the page level (I believe
vb
does that by default, not sure). Have a look at your initializateComponent
routine. Look for this line Page.Error += ....
This prevents run-time errors from percolating up the stack to the global
level. In effect, exceptions are swallowed at the page level if they
aren't
caught. You can choose to remove it or transfer your code in global asax
to
the page level error event handler.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
I have an ASP.NET application developed in Visual Studio .NET 2003.

The Application_Error in Global.asax never gains control. If the
following
is in Global.asax and I cause a Divide-by-zero the message never
appears.

protected void Application_Error( Object sender, EventArgs e )
{
Response.Write("Error" );
Server.ClearError( );
}

What am I overlooking?
 
Back
Top