Solved

Getting name of web server in global.asax used to send page error email

Posted on 2006-10-26
3
216 Views
Last Modified: 2008-03-10
We have a global.asax that someone had written to send an email everytime there was a page error. We have 3 load balanced servers now and need to be able to tell which server the error came from- Splat, Thump, or Bang.
Is there a way I can add to this code the capability to do that?

<%@ Application Language="VB" %>
<%@ Import Namespace="System.Diagnostics" %>

<script language="vb" runat="server">

Sub Application_BeginRequest(Sender as Object, E as EventArgs)
    If (Request.Path.IndexOf(chr(92)) >= 0 OR _
        System.IO.Path.GetFullPath(Request.PhysicalPath) <> Request.PhysicalPath) then
        Throw New HttpException(404, "Not Found")
    End If
End Sub
</script>


<script language="VB" runat="server" AutoEventWireup="True">

Sub Application_Error(sender As Object, e As EventArgs)
    Dim strError as String
    Dim i as Integer
    Dim ErrorInfo As Exception
        strError = "Error in: " & Request.Path & vbLf & "Url: " & Request.RawUrl & vbLf & vbLf
   
    ' Get the exception object for the last error message that occured.
    ErrorInfo = Server.GetLastError().GetBaseException()
    strError = strError & "Error Message: " & ErrorInfo.Message.ToString() & vblf & "Error Source: " & ErrorInfo.Source.ToString() & vblf & "Error Target Site: " & ErrorInfo.TargetSite.ToString() & vblf & vblf & "QueryString Data:" & vblf & "-----------------" & vblf
   
    ' Gathering QueryString information
    For i = 0 To Context.Request.QueryString.Count - 1
        strError = strError & Context.Request.QueryString.Keys(i) & ":" & vbtab & vbtab & Context.Request.QueryString(i) & vblf
    Next
    strError = strError & vblf & "Post Data:" & vblf & "----------" & vblf

    ' Gathering Post Data information
    For i = 0 To Context.Request.Form.Count - 1
        strError = strError & Context.Request.Form.Keys(i) & ":" & vbtab & vbtab & Context.Request.Form(i) & vblf
    Next
    strError = strError & vblf
   
    if (User.Identity.IsAuthenticated) then strError = strError & "User:" & vbtab & vbtab & User.Identity.Name & vblf & vblf
   
    strError = strError & "Exception Stack Trace:" & vblf & "----------------------" & vblf & Server.GetLastError.StackTrace & vblf & vblf & "Server Variables:" & vblf & "-----------------" & vblf

    ' Gathering Server Variables information
    For i = 0 To Context.Request.ServerVariables.Count - 1
        strError = strError & Context.Request.ServerVariables.Keys(i) & ":" & vbtab & vbtab & Context.Request.ServerVariables(i) & vblf
    Next
    strError = strError & vblf

[Code to send emai]
    End Sub

</script>
0
Comment
Question by:jmestep
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 300 total points
ID: 17815996
System.Environment.MachineName will return the machine name.

John
0
 

Author Comment

by:jmestep
ID: 17816118
And I can put it under:
strError = strError & vblf   ?
strError=strError & System.Environment.MachineName & vblf

I did that and it didn't break the site, I just need to wait for an error email to see if I put it in the right place.
0
 

Author Comment

by:jmestep
ID: 17816129
That worked- thank you very much
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

807 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