Common Web Mapping Application
Common_WebMappingApp_VBNet\ErrorPage.aspx.vb
' Copyright 2011 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Namespace WebMapApp
    Partial Class ErrorPage
        Inherits System.Web.UI.Page

        'Before deploying application, set showTrace to false
        ' to prevent web application users from seeing error details  
        Private showTrace As Boolean = True

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'get error message stored in session
            Dim message As String = CStr(Session("ErrorMessage"))

            'get details of error from exception stored in session
            Dim errorDetail As String = String.Empty
            Dim exception As Exception = Session("Error") '
            If Not (exception Is Nothing) Then
                Select Case exception.GetType().ToString()
                    Case "System.UnauthorizedAccessException"
                        Dim errorAccess As UnauthorizedAccessException = exception '
                        If errorAccess.StackTrace.IndexOf("SERVERCONNECTION.CONNECT", StringComparison.OrdinalIgnoreCase) > 0 Then
                            errorDetail = "Unable to connect to server. <br>"
                        End If
                End Select
                errorDetail += exception.Message
            End If

            'create response and display it
            Dim response As String
            If [String].IsNullOrEmpty(message) Then
                response = errorDetail
            Else
                response = String.Format("{0}<br>{1}", message, errorDetail.ToString())
            End If
            ErrorLabel.Text = response
            If showTrace And Not (exception Is Nothing) Then ExtendedMessage.Text = exception.StackTrace

        End Sub 'Page_Load 

    End Class
End Namespace