Displaying error message on custom error page asp.net 1.1?

Experts, I  have a web application i built with asp.net 1.1 using visual studio 2003.  In this application I edited the webconfig file to point to a custom Error page if for some reason the webpage faults.    

 <customErrors defaultRedirect="Error.aspx" mode="On">
 </customErrors>
The Error.aspx page just displays a general error message with contact information.  I want it to display the actual error with maybe a general message.  Is there a global session variable i can call up that contains this error?  
tentavariousAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amandeep Singh BhullarCommented:
When you specify the custom error On, you will be redirected to the error page but actual error will not be displayed there.
That you need to test on the local machine.
tentavariousAuthor Commented:
I am confused, how do i get the actual error message to show up on my custom error page?  For example i ran into a error where my http request was timing out, but when the error occured, the user was directed to my error page where it just said contact so and so.  I would like to have the actual error message show up on the error page.  For example the error page show show Error: http request time out, contact so and so.  There has to be a way to grab the actual error message.
tentavariousAuthor Commented:
I didn't think this would be that hard.  this is what i am attempting in my global.asax file.  First i changed my webconfig as follows:
  <customErrors  mode="Off">
 </customErrors>

Then i am trying to let my application_error event from the global file call up my error page.  The problem i am having is i cant get the actual message passed to the error page, only the location of the page causing the problem.  How can i just pass the message?

'This code doesnt pass the actual error message only the location of the webpage causing the error.
 Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Dim ex As Exception = Server.GetLastError.GetBaseException
     
        Response.Redirect("error.aspx?p_error=" & ex.Message & "")
    End Sub
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

meetingexpectationsCommented:
I'm not sure what your goal is.  Do you want your end users to see the errors or is this only for you to see for debugging purposes?  Generally speaking, you don't want to display the real error messages to your end users.  You want them to see a friendlier message while you get the messy details.

Are you using Try/Catch structures to handle errors in your code?  If so, then you will have access to the error object and all its details.  You can then do whatever you want with it such as display them to the screen, send you an e-mail, log the error, etc.
tentavariousAuthor Commented:
All my websites are internal and yes I dont care if they see the error, I have a friendly message on the top and i want the real error on the bottom.  I have way too many pages developed and i dont want to get an email or create a log entry when something doesnt work.  It is just as easy for the user to tell me the error.   Try catch doesnt always work, for example today my http request timed out  and the try catch didnt catch it.  I am trying to send the error from the Global on error event to my custom error page.
DileepanCommented:
In the Error.aspx.cs, you will need do this in the page_load

        Exception exception = Server.GetLastError();
        if (exception != null) {
            Label1.Text = exception.GetBaseException().Message; // Label1 is the asp:Label control to
                                                                                                     // display error message
        }

Also, in web.config

        <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="Error.aspx">
        </customErrors>

You will need to make sure, the Error.aspx does not get cached by browser. redirectMode=ResponseRewrite avoids a roundtrip (like Server Transfer), thereby retaining the LastError value.
tentavariousAuthor Commented:
I got an error saying that redirectMode was an unrecognized attribute.
tentavariousAuthor Commented:
Am i doing this correct, in my webconfig file?
   <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="Error.aspx">
        </customErrors>

I keep getting the asp.net error page saying unrecognized attribure 'redirectMode'
DileepanCommented:
I guess the problem is due to the .NET framework version (you will need 3.5 SP1 for this). Here is an article on that at http://blog.turlov.com/2009/01/search-engine-friendly-error-handling.html
tentavariousAuthor Commented:
So with asp.net 1.1 there is no way to do this?
tentavariousAuthor Commented:
I think i found out how i can  do it.  I am using my global file under the Application_Error method to do a server transfer, this seems to work.  The problem i am having now is that i cant get the correct exception to show up.  When i use ToString, i get a big long message i just want this part of the message:

"System.Web.HttpException: Exception of type System.Web.HttpException was thrown. ---> System.IO.FileNotFoundException: c:\inetpub\wwwroot\BobcatProduction\tege.aspx







Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
        Dim ex As Exception
        ex = Server.GetLastError
        Dim erroval As String = ex.ToString
        If Not ex Is Nothing Then
            Server.Transfer("Error.aspx?p_error=" & erroval & "")
        End If
       
    End Sub

Open in new window

DileepanCommented:
The simplest approach now should be to add the exception object to Session and display the same in error page. Adding to Session should happen before Server.Transfer
tentavariousAuthor Commented:
Are you saying to use session variables in the global application error event?  Like so:
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when an error occurs
        Dim ex As Exception
        ex = Server.GetLastError
            Session("set_error") = ex.Message
        Server.Transfer("Error.aspx")
    End Sub

When i tried using sessions i got this error:
Session state is not available in this context
tentavariousAuthor Commented:
I have yet to find an answer and although the comments were helpful, none of them correctly addressed the problem.  Can i please close this question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.