473,387 Members | 1,791 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.

Error Pages, Static Error Variables and all the stuff inbetween

so I was looking at an example on codeproject.com that talked about how to
globalize your error handling. I was extremely confused by some code. Id
appreciate if someone could help me out by understanding this.

URL if anyone is interested:
http://www.codeproject.com/aspnet/Jc...asp#xx726891xx
1) Ok, so in short, the way to do this error handling is to set a STATIC
variable in some class whenever an error occurs. Global.aspx file:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Utilities.LastError = Server.GetLastError()
End Sub

2) Decl of Utility Class:
Public Class Utilities
Public Shared LastError As System.Exception
End Class

3) Obviously set the customErrors handler in web.config:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">

4) In the ErrorPage.aspx page, you have the following code to get the error
back from the STATIC variable:
With Utilities.LastError.InnerException
Dim r0 As DataRow = t.NewRow
r0(0) = "Message"
r0(1) = .Message
t.Rows.Add(r0)
Dim r1 As DataRow = t.NewRow
r1(0) = "StackTrace"
r1(1) = .StackTrace.Replace(vbCr, "<br>")
t.Rows.Add(r1)
Dim r2 As DataRow = t.NewRow
r2(0) = "Source"
r2(1) = .Source
t.Rows.Add(r2)
End With

Sorry for the mixing up of concepts/code between c# and vb.net, but heres my
problem: I understand what static variables are. And I understand that once
set, they are set for the whole application process. (Im stating process -
but maybe its threads. I dont really know. Does IIS choose from pool or
create one thread per one hit to the application webiste?)

Anyways, so if someone(User1) were to come on the website and an error
occurred, the static variable would be set and the person would be
redirected. Now what in the name of the world would happen IFF before the
redirect to the errorpage, User1's processing gets preempted and ANOTHER
user (User2) were to hit the website and get a different exception. The SAME
static variable would be set to a new error. Right?

Now processing continues and User1's error page renders with User2's error
code???!

I dont get it.

Girish

Nov 18 '05 #1
3 1486
Hi Girish,
Thanks for posting in the community!
I've read the tech article you provided and your question is on the means
the author used to store the server error in Application_Error event when
unhandled error occurs on server , yes?

The author used a static class member to store the error exception. Of
course, I don't quite agree to this solution since the static member of a
class is accessable to the whole application as you mentioned and will
cause concurrence issue.

The reason why we need to pre-store the error info in Application_Error is
because by default the ASP.NET will clear the server error and restart a
new session after the Application_Error event and before the user
redirected to the "defaultErrorPage" you set in the <customError> element
in web.config file. You can try using the Server.GetLastError in
the errorpage's Page_load event to see whether you can get the info, you
'll get a null value. However, we can workaround this by manually use
Server.Transfer to redirect user to the error page in Application_Error
event, for example:
protected void Application_Error(Object sender, EventArgs e)
{
Server.Transfer("customerrorpage.aspx");
}
Thus, we can still use Server.GetLastError to get the error info. No
additional store needed, of course no concurrece problem. Also, I've
discussed this issue in another post ,here is its web link in google:

#DefaultRedirect Problem
http://groups.google.com/groups?hl=e...ame=right&th=c
4385267d67065bd&seekm=%24EyuIys6DHA.568%40cpmsftng xa07.phx.gbl#link1

You may also have a look to see my detailed description.

Furthur more, I think the "Log4Net" logging component the author has
mentioned , I think it is a very cool component.
#log4net
http://log4net.sourceforge.net/

Please check out the above items. If you feel anything unclear, please feel
free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #2
Hi Girish,

Have you had a chance to check out my suggestions or have you got any
further ideas on this issue? If you need any further help, please feel free
to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3
Yes, thanks Steven. Im not using global static variables. Ive used the
server.transfer method call to facilitate my error handling.

Thanks for your help.
Girish

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:i2****************@cpmsftngxa06.phx.gbl...
Hi Girish,

Have you had a chance to check out my suggestions or have you got any
further ideas on this issue? If you need any further help, please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4

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

Similar topics

1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
12
by: zig | last post by:
I've posted this on alt.comp.lang.coldfusion, but is predominantly a javascript problem: I have a CF query which returns several rows of records. I wanted to have a checkbox on each record of...
2
by: Zuel | last post by:
Hi Folks! I am developing with VB ASP .net and C#. I received an error while compiling, BC30652. This error says that a reference to an assembly missing. The Details are this. 1 VB ASP.net...
28
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
3
by: Colin Desmond | last post by:
I have an MFC Extension DLL that I have flicked the /clr switch on and made a few other tweaks so it compiles and runs in a managed MFC applicaiton. The DLL contains a number of classes which...
2
by: maansi.creations | last post by:
Service unavailable error comes randomly while accessing our website and gets alright in matter of seconds....Could some one tell the possible reasons for these to happen: i got a earlier...
1
by: shivkumar2004 | last post by:
Hi!, I am developing a chat system using vb.net in vs 2005. I am getting the following error while registering the events. error details: System.InvalidOperationException was unhandled...
0
by: shivkumar2004 | last post by:
Hi, I m getting the following error while registering the events on client appl. error: "An error occurred creating the form. See Exception.InnerException for details. The error is: Exception...
10
by: Pramod | last post by:
Hello to all of you, I want to know that what's the use to create static object. Thanks You Pramod Sahgal
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: 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
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: 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:
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,...
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...

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.