473,890 Members | 5,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using Global asax for error trapping

JP
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 log as well as fire up my email
class and generate an email to send me the error. But no matter what I do, I
still get the icky looking yellow and white error screens.

I’ve turned on customErrors in the web.config but not default URL setting.
The pages don’t have Page_Error method in them so I would except the error to
move next up in the hierarchy which would be Application_Err or. There are so
many pages in this project, I really cant trap general errors at the page
level. What am I doing wrong?????

protected void Application_Err or(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastE rror().GetBaseE xception();
string err ="Error Caught in Application_Err or event\n" +
"Error in: " + Request.Url.ToS tring() +"\nError Message:" +
objErr.Message. ToString()+ "\nStack Trace:" + objErr.StackTra ce.ToString();

EventLog.WriteE ntry("Sample_We bApp",err,Event LogEntryType.Er ror);
Server.ClearErr or();
classes.email Email = new classes.email() ;
bool Status = Email.GenerateE mail("ERROR",nu ll,err.ToString ());
Response.Redire ct("errorpage.a spx");

}

--
JP
..NET Software Developer

Nov 22 '05 #1
3 3340
By the time this event fires, it is too late to do a redirect. There is no
request at this point.

If you want to have central error handling, but be able to redirect, then
create a base page class that handles the error event. Then have every other
page in your application inherit from this page.

"JP" <JP@discussions .microsoft.com> wrote in message
news:30******** *************** ***********@mic rosoft.com...
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 log as well as fire up my email
class and generate an email to send me the error. But no matter what I do,
I
still get the icky looking yellow and white error screens.

I've turned on customErrors in the web.config but not default URL setting.
The pages don't have Page_Error method in them so I would except the error
to
move next up in the hierarchy which would be Application_Err or. There are
so
many pages in this project, I really cant trap general errors at the page
level. What am I doing wrong?????

protected void Application_Err or(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastE rror().GetBaseE xception();
string err ="Error Caught in Application_Err or event\n" +
"Error in: " + Request.Url.ToS tring() +"\nError Message:" +
objErr.Message. ToString()+ "\nStack Trace:" +
objErr.StackTra ce.ToString();

EventLog.WriteE ntry("Sample_We bApp",err,Event LogEntryType.Er ror);
Server.ClearErr or();
classes.email Email = new classes.email() ;
bool Status = Email.GenerateE mail("ERROR",nu ll,err.ToString ());
Response.Redire ct("errorpage.a spx");

}

--
JP
.NET Software Developer

Nov 22 '05 #2
JP
Ok, excluding the redirect line of code. At the point Im saying its noteven
getting to this point. My understanding was that all application error with
the exception of http error, ie 404,500 ect get passed to the
Application_Err or method in the global.asax if there is no Page_Error method
to handle an error at the page level. Its as though it never makes it to the
global.asax.

Strange that intllisense will allow Response.Redire ct but that you cant use
it. I see ehat your saying to do, Im just trying to understand that
everything Ive read says errors get passed to this method, yet Im not getting
ANY results.

Thoughts?
--
JP
..NET Software Develper
"Marina" wrote:
By the time this event fires, it is too late to do a redirect. There is no
request at this point.

If you want to have central error handling, but be able to redirect, then
create a base page class that handles the error event. Then have every other
page in your application inherit from this page.

"JP" <JP@discussions .microsoft.com> wrote in message
news:30******** *************** ***********@mic rosoft.com...
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 log as well as fire up my email
class and generate an email to send me the error. But no matter what I do,
I
still get the icky looking yellow and white error screens.

I've turned on customErrors in the web.config but not default URL setting.
The pages don't have Page_Error method in them so I would except the error
to
move next up in the hierarchy which would be Application_Err or. There are
so
many pages in this project, I really cant trap general errors at the page
level. What am I doing wrong?????

protected void Application_Err or(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastE rror().GetBaseE xception();
string err ="Error Caught in Application_Err or event\n" +
"Error in: " + Request.Url.ToS tring() +"\nError Message:" +
objErr.Message. ToString()+ "\nStack Trace:" +
objErr.StackTra ce.ToString();

EventLog.WriteE ntry("Sample_We bApp",err,Event LogEntryType.Er ror);
Server.ClearErr or();
classes.email Email = new classes.email() ;
bool Status = Email.GenerateE mail("ERROR",nu ll,err.ToString ());
Response.Redire ct("errorpage.a spx");

}

--
JP
.NET Software Developer


Nov 22 '05 #3
What if you are using a bare bone sub such as adding 1 to a counter and
seeing on another page if its change ?
My first goal would be to see if this is triggered or if there is some kind
of error in trapping the error that prevents this.

Also try to use off in the web.config for a start. The normal process is
that you would go to the custom page after the global handler. This might be
the problem.

--
Patrice

"JP" <JP@discussions .microsoft.com> a crit dans le message de
news:9B******** *************** ***********@mic rosoft.com...
Ok, excluding the redirect line of code. At the point Im saying its noteven getting to this point. My understanding was that all application error with the exception of http error, ie 404,500 ect get passed to the
Application_Err or method in the global.asax if there is no Page_Error method to handle an error at the page level. Its as though it never makes it to the global.asax.

Strange that intllisense will allow Response.Redire ct but that you cant use it. I see ehat your saying to do, Im just trying to understand that
everything Ive read says errors get passed to this method, yet Im not getting ANY results.

Thoughts?
--
JP
.NET Software Develper
"Marina" wrote:
By the time this event fires, it is too late to do a redirect. There is no request at this point.

If you want to have central error handling, but be able to redirect, then create a base page class that handles the error event. Then have every other page in your application inherit from this page.

"JP" <JP@discussions .microsoft.com> wrote in message
news:30******** *************** ***********@mic rosoft.com...
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 log as well as fire up my email class and generate an email to send me the error. But no matter what I do, I
still get the icky looking yellow and white error screens.

I've turned on customErrors in the web.config but not default URL setting. The pages don't have Page_Error method in them so I would except the error to
move next up in the hierarchy which would be Application_Err or. There are so
many pages in this project, I really cant trap general errors at the page level. What am I doing wrong?????

protected void Application_Err or(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastE rror().GetBaseE xception();
string err ="Error Caught in Application_Err or event\n" +
"Error in: " + Request.Url.ToS tring() +"\nError Message:" +
objErr.Message. ToString()+ "\nStack Trace:" +
objErr.StackTra ce.ToString();

EventLog.WriteE ntry("Sample_We bApp",err,Event LogEntryType.Er ror);
Server.ClearErr or();
classes.email Email = new classes.email() ;
bool Status = Email.GenerateE mail("ERROR",nu ll,err.ToString ());
Response.Redire ct("errorpage.a spx");

}

--
JP
.NET Software Developer


Nov 22 '05 #4

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

Similar topics

3
661
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 log as well as fire up my email class and generate an email to send me the error. But no matter what I do, I still get the icky looking yellow and white error screens. I’ve turned on customErrors in the web.config but not default URL setting....
12
2427
by: Luther Hert | last post by:
While trying to work through textbook lessons for Vb.net Step by Step,Version 2003, Chapter 22, the first step is to create a new Web application Project,using the ASP.Net Application icon in the Visual Basic Projects folder. When I select the ASP.Net Application icon and type in http://localhost/MyWebCalculator, I recieve an error in a dialogue box stating: MS Development Environment Dialogue Box error message:
14
445
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 to the administrator... i tried the following below but can't get it working. I did have it working a while ago...but have had no success with this.... any ideas? heres the code (simplistic) from the global.asax file:
22
3820
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to manipulate them. It starts > and ends with <script></script> tags. > > Yours looks like a compiled version of it.
2
2308
by: Michael Tissington | last post by:
How do I specify the CodeFile for my Global.asax file ? According to the documentation I can use the CodeFile attribute with Application, however when I try to use this I get an error saying that it not a valid attribute. <%@ Application Language="C#" Inherits="SQLView.Global" CodeFile="Global.asax.cs"%> --
0
1180
by: seanmccormick1 | last post by:
We are having trouble trapping errors that occur in the WSE 2.0 code. Our error handling/logging for our web services happens in the Global.asax Application_OnError method, but it does not seem to run that part of the code if there is an error thrown by the Microsoft.Web.Services2.Security code. For instance, if we skew the clocks by more then an hour between client and server on different machines, we can get the ...
1
3325
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 probably more common than HttpHandlers, but could still stand to be advertised a bit more. HttpModules are incredibly easy to explain, so this will hopefully be a short-ish post. Simply put, HttpModules are portable versions of the global.asax....
8
3551
by: Doug | last post by:
Visual Studio 2005, SQL Server 2000, ASP.NET/VB.NET Not allowed to use the ASPNET machine account in SQL Server (very strict environment). Need to use Windows authentication, so we use "Identity Impersonate=true" in the web.config file. Trying to implement a system-wide error trapping mechanism. Nothing fancy, just writing to a log file. The recommended procedure was to
4
3060
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 debugger unless I add a Global.asax file. When I do that and then try to run the debugger I receive error 403. If I remove the Global.asax file things work fine. The Global.asax file is the one generated by VS 2005 - I don't try to add anything...
16
5054
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="<Namespace>." %> I've done a lot of things I've found on the web to no avial, but here are some unique things about what is happening to me.
0
9979
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
10924
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10463
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8017
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7170
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6049
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4681
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4275
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3281
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.