Go Premium for a chance to win a PS4. Enter to Win


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

Posted on 2006-10-26
Medium Priority
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 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
    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
    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
    strError = strError & vblf

[Code to send emai]
    End Sub

Question by:jmestep
  • 2
LVL 10

Accepted Solution

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


Author Comment

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.

Author Comment

ID: 17816129
That worked- thank you very much

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

927 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