Solved

ASP.NET Error Handler

Posted on 2008-09-30
8
205 Views
Last Modified: 2011-10-19
I have a .net web application and in my config file i have

<customErrors mode="On" defaultRedirect="~/error.aspx" />
Then on the error page I use Server.GetLastError.ToString which is not working it returns "Object reference not set to an instance of an object."

How do i get the error the redirected the user to the default error page so i can correct it.

Thank you
0
Comment
Question by:jimseiwert
  • 5
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
ID: 22607168
try this
Sub Page_Error(sender as Object, e as EventArgs)

  dim PageException as string = Server.GetLastError().ToString()
  dim strBuild as new StringBuilder()
  strBuild.Append("Exception!")
  strBuild.Append(PageException)

  Response.Write(strBuild.ToString())
  Context.ClearError()

End Sub
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22607190
also if you are create yr method in class so u need to use this
 HttpContext.Current
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 22607484
this is what i got
error.bmp
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22607605
please dont put this on page load event . it is not correct ... check this post for details

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_21134839.html
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:jimseiwert
ID: 22607674
Ops, i just posted my comment on the wrong thread. I added the below code and placed a break point on the sub you told be to add but it never gets called on my generic error page that the web.config redirects it to. What am i missing?

Thank you for your patience
Imports System.Web

Imports System.Web.SessionState

Imports System.Web.Mail

Imports System.Diagnostics

Partial Class Sessions

    Inherits System.Web.UI.Page
 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 

    End Sub

    Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
 

        Dim PageException As String = Server.GetLastError().ToString()

        Dim strBuild As New StringBuilder()

        strBuild.Append("Exception!")

        strBuild.Append(PageException)
 

        Response.Write(strBuild.ToString())

        Context.ClearError()
 

    End Sub

Open in new window

0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22607739
see that event called when some error comes in your page ,, nor that page is loaded .. try to throw some error on page laod and see
0
 
LVL 2

Author Comment

by:jimseiwert
ID: 22607774
but this is the generic page that the web.config file calls when the application has an error. If i force an error then the server,getlasterror will retun the wrong error wont it ?
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22611631
see this Page_Error error call when that page has error , for application related error you need to write code in global.asax in application_error event
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now