[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Need to direct user to a friendly error page and EMail exception details to the developer.

Asked by Dovberman in Visual Studio, Programming for ASP.NET

Tags: Microsoft, Visual Studio, 2005

When an error occurs, the friendly error page, errorpage.aspx needs to open. A detailed exception message needs to be Emailed to the developer.

I copied code from references. The global.aspx handles all errors. However the friendly error page does not open. I, the developer am not receiving an error detail mail message.

What am I missing?

This is what I have:

web.config

       <customErrors mode="RemoteOnly"   defaultRedirect="ErrorPage.aspx">
   
        </customErrors>
       
      </system.web>
      <system.net>
            <mailSettings>
                  <smtp from="myname@mailsite.com">
                        <network
                        host="localhost"
                        password=""
                        userName=""/>
                  </smtp>
            </mailSettings>
      </system.net>
</configuration>

ErrorPage.aspx.vb

Imports System.Net.Mail
Imports System.Diagnostics
Partial Class ErrorPage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objClient As New SmtpClient
        Dim objEMail As New MailMessage
        Dim strTo As String = ""
        Dim strUserName As String = ""
        Dim usrCurrent As MembershipUser = Membership.GetUser()
        Dim strErrorMessage As String = ""

        If Not usrCurrent Is Nothing Then
            strUserName = usrCurrent.UserName
            strErrorMessage = "Thank you:" & strUserName _
            & " The error has been Emailed to our development staff."
        End If
        txtErrorMsg.Text = strErrorMessage
    End Sub
End Class

Global.asax

<%@ Application Language="VB" %>

<script runat="server">

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
    End Sub
   
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
    End Sub
       
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
        'Get exception details
        ' Give the user some information, but
        ' stay on the default page
        Dim ex As Exception = Server.GetLastError()
        Response.Write("<h2>Global Page Error</h2>" & Chr(10) & "")
        Response.Write("<p>" + ex.Message + "</p>" & Chr(10) & "")
        Response.Write("Return to the <a href='Default.aspx'>" + "Default Page</a>" & Chr(10) & "")
   
   
        If ex IsNot Nothing Then
            Try
                MsgBox("Error Detected", MsgBoxStyle.Information, "Error")
               
                'Email the administrator with information that an error has occurred
                '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
                Const ToAndFromAddress As String = "david.martin@fema.gov"

                '(1) Create the MailMessage instance
                Dim msgError As New System.Net.Mail.MailMessage(ToAndFromAddress, ToAndFromAddress)

                '(2) Assign the MailMessage's properties
                msgError.Subject = "An unhandled exception occurred!"
           
                msgError.Body = String.Format("An unhandled exception occurred:{0}Message: {1}{0}{0} Stack Trace:{0}{2}", _
                System.Environment.NewLine, ex.Message, ex.StackTrace)

                msgError.IsBodyHtml = False

                '(3) Create the SmtpClient object
                Dim smtp As New System.Net.Mail.SmtpClient

                '(4) Send the MailMessage (will use the Web.config settings)
                smtp.Send(msgError)
            Catch
                'Whoops, some problem sending email!
                'Just send the user onto ErrorPage.aspx...
            End Try
        End If
       
        ' Clear the error from the server
        Server.ClearError()

    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a session ends.
        ' Note: The Session_End event is raised only when the sessionstate mode
        ' is set to InProc in the Web.config file. If session mode is set to StateServer
        ' or SQLServer, the event is not raised.
    End Sub
       
</script>






[+][-]05/06/08 08:40 AM, ID: 21508242Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Visual Studio, Programming for ASP.NET
Tags: Microsoft, Visual Studio, 2005
Sign Up Now!
Solution Provided By: rlively
Participating Experts: 2
Solution Grade: A
 
[+][-]05/05/08 11:56 AM, ID: 21502146Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/05/08 12:13 PM, ID: 21502242Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/05/08 01:09 PM, ID: 21502596Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/05/08 02:18 PM, ID: 21503106Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/05/08 02:57 PM, ID: 21503340Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/05/08 03:26 PM, ID: 21503530Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628