Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Error Handler

Posted on 2008-09-30
8
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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