Frustrations with Error Logging

S

sean_walsh

Hi

From classic ASP, I had a custom error handling situation that was
quite simple. Errors were all redirected to Error.asp. This page would
check 2 settings, EmailErrorMessage and DisplayErrorMessage. If
EmailErrorMessage was true, it would send an email with the error
details. If DisplayErrorMessage was true, it would display the message
on screen. Also, if an Administrator was logged in, it would display
the message as they could then handle it.

Now in .NET this is proving EXTREMELY frustrating.

Please correct me if my logic here is wrong: In the web.config file, I
can add the lines:
<customErrors mode="On" defaultRedirect="/Error.aspx">
<error statusCode="400" redirect="/Error.aspx?err=400" />
<error statusCode="401" redirect="/Error.aspx?err=401" />
<error statusCode="403" redirect="/Error.aspx?err=403" />
<error statusCode="404" redirect="/Error.aspx?err=404" />
<error statusCode="408" redirect="/Error.aspx?err=408" />
<error statusCode="500" redirect="/Error.aspx?err=500" />
<error statusCode="503" redirect="/Error.aspx?err=503" />
</customErrors>

That looks like an elegant and simple solution. BUT, error.aspx won't
have access to the error object as this is effectively a redirect, and
the error object is lost.

Now I've seen that you can ("should") handle your error in the
Global.asax area and then transfer to a simple HTML page. But this is
just stupid. Firstly, I'm filling up my global.asax with error
handling code. Secondly, I can send the email with the error info from
this point, but when I redirect to the error page, I lose the ability
to display the error message on screen to administrators.

SO, I can try putting this into global.asax:
void Application_Error(object sender, EventArgs e)
{
Server.Transfer("/Error.aspx");
}

BUT, when this gets to my error page, this new error object doesn't
have the info I would like. I get the error with:
Exception objError = Server.GetLastError().GetBaseException();

But this doesn't have the error code, or line number, etc. I would
like to (for example) be able to filter out the 404 errors, as these
can be handled with a simple redirect to the home page, as that
content has moved, and it's not worth showing an error page for it.
But I can't do that now!

I don't get this new logic. For example, it's got a property
objError.Source, which gives a result: "System.Web". Of course &(%@
System.Web created the error - it's a website system!!!!!

Why did they take away the very simple and useful Line Number and
Error Number (error code)???

Anyone got a good idea on what to do?
 
S

sloan

Here is one way to make a helper call.

Create a class.


public class WebPageExceptionWrapper
{

public static void HandleException( Page p , Exception ex ) //by sending
in the Page, you have alot of control for redirects and stuff
{
if(null==p)
{
return;
}

p.Response.Write (ex.Message);

bool redirect = true; //just a crappy way to show you can optionally
redirect.
if(redirect)
{
p.Response.Redirect(http://www.microsoft.com);
}

}


}



then on your aspx.cs files


public void TrySomething()
{

try
{
int i = 0;
int j = 0;
int k = i/j;

}
catch(Exception ex)
{
WebPageExceptionWrapper.HandleException(this.Page , ex);
}

}



Unforunately, I cannot agree with you on the "helpful error numbers".
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!234.entry


Exception Handling is a slightly different mindset (as opposed to
errorhandling in vb/asp terms).
And IMHO is a much better solution.

Follow my blog entry and find the great article by Krzysztof Cwalina.

Good luck on your endeavors.


This is ONE idea. There are others. But I think this is a good "bridge the
gap" idea for you coming from asp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error Handling 2
Error Handling Question(1) 3
HTTP Error 404 1
CustomErrors! What is going on? 0
customErrors 1
CustomError Problem 4
<customErrors 3
Custom Error Pages 2

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top