Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

ASP.NET Error Handler

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
jimseiwert
Asked:
jimseiwert
  • 5
  • 3
1 Solution
 
Gyanendra SinghArchitectCommented:
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
 
Gyanendra SinghArchitectCommented:
also if you are create yr method in class so u need to use this
 HttpContext.Current
0
 
jimseiwertAuthor Commented:
this is what i got
error.bmp
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
Gyanendra SinghArchitectCommented:
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
 
jimseiwertAuthor Commented:
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
 
Gyanendra SinghArchitectCommented:
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
 
jimseiwertAuthor Commented:
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
 
Gyanendra SinghArchitectCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now