Web.Config - customErrors

J

John Smith

I am trying to implement custom error pages and I get this error message:

****************************************************************************
********
****************************************************************************
********
Server Error in '/mfg' Application.
----------------------------------------------------------------------------
----

Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed.

Details: To enable the details of this specific error message to be viewable
on the local server machine, please create a <customErrors> tag within a
"web.config" configuration file located in the root directory of the current
web application. This <customErrors> tag should then have its "mode"
attribute set to "RemoteOnly". To enable the details to be viewable on
remote machines, please set "mode" to "Off".


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
<customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
****************************************************************************
********
****************************************************************************
********

My my customErrors tag in the Web.Config file looks like this:

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

I am working directly on the server (Win2k). Any ideas?

Thanx.
 
B

Ben Dewey

If you change your customErrors to Off with no defaultRedirect, do you still
get an error?

If not, try switching the order of the defaultRedirect and mode attributes.
Its a long shot but it might work. Let me know how it works out.
 
J

John Smith

I made a change to my customErrors tag to:

<customErrors defaultRedirect="errors.aspx" mode="RemoteOnly"/>

I tested with just an HTML file and it worked okay. I eliminated the the
web.config as the problem it is now within my code. I found out that I am
actually having a problem with this code:

****************************************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'*** UserID Works fine ***
Dim UserID As Integer = Session("UserID")
Response.Write("UserID = " & UserID & "<BR>")

'*** Problem resides in here ***
Dim ErrorMessage As String = Server.GetLastError.ToString
Response.Write("ErrorMessage = " & ErrorMessage & "<BR>")

End Sub
****************************************************************************

Any ideas on what I am doing wrong?

Thanx
 
B

Ben Dewey

You need to check the Server.GetLastError before you call ToString on it.

Example:
If Server.GetLastError Is Nothing = False Then
Dim ErrorMessage As String = Server.GetLastError.ToString()
Response.Write("ErrorMessage = " & ErrorMessage & "<BR>")
End If
 
J

John Smith

I changed my code to check to see if it is nothing. I manually threw an
applicationexception and it is not returning it. it is returning as
nothing. any ideas?
 
B

Ben Dewey

My mistake, you don't need to check if the error is nothing, you do, on the
other hand, need to have the code for the Page Error in the Page_Error event
handler.

Example:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call throwAnError()
End Sub

Private Sub throwAnError()
Throw New ApplicationException("some error")
End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Dim ErrorMessage As String = Server.GetLastError.Message
Response.Write("ErrorMessage = " & ErrorMessage & "<BR>")
End Sub
 
J

John Smith

Thanx that works good, but I found another solution. I added
Server.Transfer("customerror.aspx") in the Application_Error in the
global.asax file.

Thanx for all of your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top