Solved

ASP.NET Error Handler

Posted on 2008-09-30
8
208 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Iteration Help (Asp.net VB) 5 24
System.net.Sockets Error 5 28
VB.net Open video relating to control 2 20
How to repeat the data 4 18
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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