Solved

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

Posted on 2006-10-26
3
214 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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