[RESOLVED]Microsoft?? getting information from Server.GetLastError in webPages

Following this
post
, "gracefully responding to unhandled exceptions…"

Couple of questions:

does the handler need to be in a global.asax file?

This is what I have so far….

var ex = HttpContext.Current.Server.GetLastError();

if (LastError != null)
    {
        var y = ex.Source;
        var z = ex.TargetSite;
        var s = ex.InnerException;
        var t = ex.Message;
        var u = ex.StackTrace;
        var v = ex.HelpLink;
      
            
    
    }

And my webconfig:

<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorHandling/BTError.cshtml" >
    <error statusCode="404" redirect="~/ErrorHandling/404.cshtml" />
    </customErrors> 

Supposed I wanted to store those in my db. How can I find out how long my nvars need to be to store this?

What are the magic search words I need to be aware of to be able to find something online? Just finding old stuff.

wavemaster

Supposed I wanted to store those in my db. How can I find out how long my nvars need to be to store this?

Honestly, I have no idea of the limits of these particular fields. I tried digging around the source but it really wasn’t very helpful. It might be a matter of trial and error, although I know some properties like the StackTrace can get mighty large and
you might end up wandering around the NVARCHAR(MAX) length for many of the properties.

Any thoughts on if this needs to be in global.asx?

wavemaster

does the handler need to be in a global.asax file?

Yes, that will probably be the best place for it.

You can see an example detailing
how to process and handle "unhandled exceptions" within this similar article
. It recommends placing the following in the Application_Error method of the Global.asax file :

protected void Application_Error(object sender, EventArgs e)
{
    // Transfer the user to the appropriate custom error page
    HttpException lastErrorWrapper = Server.GetLastError() as HttpException;

    if (lastErrorWrapper.GetHttpCode() == 404)
    {
           Server.Transfer("~/ErrorPages/404.aspx");
    }
    else
    {
           Server.Transfer("~/ErrorPages/Oops.aspx");
    }
}

Rion, thanks for your help.

I have abandoned my effort to write my own code. Too little information available that is current and applicable to webpages. Don’t have time to reinvent the wheel.

Currently working on implementing Elmah.

Leave a Reply