473,406 Members | 2,371 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,406 software developers and data experts.

How to test for HttpException

I have this code in Global.asax, but it doesn't compile yet.
What am i doing wrong?
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string msg = objErr.ToString();
if (objErr.GetType is HttpException)
{
// Need to bypass 404 errors
ErrNotify.LogError(msg);
}
else
{
ErrNotify.LogError(msg);
}
Server.ClearError();
}
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)
Dec 4 '06 #1
3 2079
Hi,

Arne Garvander wrote:
I have this code in Global.asax, but it doesn't compile yet.
What am i doing wrong?
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string msg = objErr.ToString();
I would rather use

string msg = objErr.Message;
if (objErr.GetType is HttpException)
That should be

if ( objErr is HttpException )
{
// Need to bypass 404 errors
ErrNotify.LogError(msg);
}
else
{
ErrNotify.LogError(msg);
Did you notice that you do exactly the same in both cases?
}
Server.ClearError();
}
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 4 '06 #2
Hi Laurent,

<snip>
> Exception objErr = Server.GetLastError().GetBaseException();
string msg = objErr.ToString();

I would rather use

string msg = objErr.Message;
Exception.ToString() provides details such as the StackTrace and the
StackTraces of the InnerException (recursively). Also, when deriving from
Exception you can override ToString to add more details about the exception
that the Message property doesn't provide.

So for error logging purposes, such as the OP's code, ToString is probably a
better choice.

<snip>

--
Dave Sexton
Dec 5 '06 #3
Hi Dave,

Dave Sexton wrote:
Hi Laurent,

<snip>
>> Exception objErr = Server.GetLastError().GetBaseException();
string msg = objErr.ToString();
I would rather use

string msg = objErr.Message;

Exception.ToString() provides details such as the StackTrace and the
StackTraces of the InnerException (recursively). Also, when deriving from
Exception you can override ToString to add more details about the exception
that the Message property doesn't provide.

So for error logging purposes, such as the OP's code, ToString is probably a
better choice.

<snip>
Yes, you're right. Don't know why, I was sure that the OP used msg to
display a warning to the user.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 5 '06 #4

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

Similar topics

0
by: Steve | last post by:
Hi All, I keep getting the "System.Web.HttpException: Request timed out." error message when I was uploading image files (about 400 image files) to SQL table, all those image files are FTP to...
3
by: Gvnn | last post by:
Hi, I've a little problem, i've an asp.net page, with a runat server form, like this: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="index.aspx.vb" Inherits="indexGstPro"%> <HTML>...
0
by: Jack Wright | last post by:
Dear All, I have a web Application "http://localhost/Web/WebForm1.aspx" that calls a WebService from "http://localhost/webserviceapp/service1.asmx"...I have set the executionTimeout to 10 secs in...
0
by: Frank | last post by:
Does anyone have any clues as to what might have caused this error? Only the startup web page uses ASP compatibility mode. I've tested this thru 100000s of cycles, and this recently appears in one...
3
by: Rolf Gossen | last post by:
Hello NG, In my Web-Application I want to redirect the User to the Login-Page whenever his Session has timed out. According to a lot of NewsGroup Entries this can be achieved by the following...
2
by: MattB | last post by:
I'm trying to implement this MS "best practice" to test for canonicalization issues in my web application. I went to http://support.microsoft.com/?kbid=887459 and pasted their code into my...
2
by: Dave F. | last post by:
I just installed my ASP.NET app on a Win 2k server. I installed the files in a folder on D: and setup a virtual directory in IIS Default web. We had to install the Framework 1.1 and SP on this...
1
by: dima | last post by:
Hi All, I know some of you had this problem in production. Did anyone find out how to fix this problem or what is the cause of it? System.Web.HttpException: Invalid_Viewstate ...
0
by: eswanson | last post by:
I have a site that has multiple web site projects. I got it working on my windows xp sp2 computer in pre-compiled mode. I created a new site on a windows 2003 server and copied the pre-compiled...
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: 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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
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...

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.