Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now