Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Server.GetLastError is Nothing on custom error page

Posted on 2004-09-17
4
Medium Priority
?
904 Views
Last Modified: 2008-09-30
I'm trying to write a custom error page, to display the error message within a page matching the "house style". I thought that I could use Server.GetLastError to get the exception that was thrown, but it has a value of "Nothing".

In my web.config I have:

    <customErrors mode="On"  defaultRedirect="error.aspx" />

And in the code-behind of error.aspx I have:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ex As Exception = Server.GetLastError   ' <--- ex is Nothing at this point
        lblError.Text = ex.Message

    End Sub

This is making my custom error page pretty useless. What am I doing wrong?
0
Comment
Question by:crescendo
[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
4 Comments
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 800 total points
ID: 12083610
0
 
LVL 33

Assisted Solution

by:raterus
raterus earned 200 total points
ID: 12083964
The defaultRedirect occurs AFTER the server has processed all the error junk, if you want to get the last error, you either have to do it in Page_Error or Application_Error

--Michael
0
 
LVL 2

Expert Comment

by:jimseiwert
ID: 22607662
Maybe i am missing something but i have the following code in the pack of my page, but the sub Page_error never gets called when the error page gets loaded. 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: 22607736
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

Featured Post

Industry Leaders: 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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