473,387 Members | 1,664 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,387 software developers and data experts.

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_Error. 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_Error(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastError().GetBaseException();
string err ="Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +"\nError Message:" +
objErr.Message.ToString()+ "\nStack Trace:" + objErr.StackTrace.ToString();

EventLog.WriteEntry("Sample_WebApp",err,EventLogEn tryType.Error);
Server.ClearError();
classes.email Email = new classes.email();
bool Status = Email.GenerateEmail("ERROR",null,err.ToString());
Response.Redirect("errorpage.aspx");

}

--
JP
..NET Software Developer

Nov 22 '05 #1
3 3281
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**********************************@microsof t.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_Error. 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_Error(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastError().GetBaseException();
string err ="Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +"\nError Message:" +
objErr.Message.ToString()+ "\nStack Trace:" +
objErr.StackTrace.ToString();

EventLog.WriteEntry("Sample_WebApp",err,EventLogEn tryType.Error);
Server.ClearError();
classes.email Email = new classes.email();
bool Status = Email.GenerateEmail("ERROR",null,err.ToString());
Response.Redirect("errorpage.aspx");

}

--
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_Error 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.Redirect 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**********************************@microsof t.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_Error. 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_Error(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastError().GetBaseException();
string err ="Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +"\nError Message:" +
objErr.Message.ToString()+ "\nStack Trace:" +
objErr.StackTrace.ToString();

EventLog.WriteEntry("Sample_WebApp",err,EventLogEn tryType.Error);
Server.ClearError();
classes.email Email = new classes.email();
bool Status = Email.GenerateEmail("ERROR",null,err.ToString());
Response.Redirect("errorpage.aspx");

}

--
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**********************************@microsof t.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_Error 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.Redirect 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**********************************@microsof t.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_Error. 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_Error(Object sender, EventArgs e)
{

Exception objErr = Server.GetLastError().GetBaseException();
string err ="Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +"\nError Message:" +
objErr.Message.ToString()+ "\nStack Trace:" +
objErr.StackTrace.ToString();

EventLog.WriteEntry("Sample_WebApp",err,EventLogEn tryType.Error);
Server.ClearError();
classes.email Email = new classes.email();
bool Status = Email.GenerateEmail("ERROR",null,err.ToString());
Response.Redirect("errorpage.aspx");

}

--
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
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...
12
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...
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...
22
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...
2
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...
0
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...
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...
8
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...
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...
16
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: <%@...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.