jmestep
asked on
Getting name of web server in global.asax used to send page error email
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.Diagnost ics" %>
<script language="vb" runat="server">
Sub Application_BeginRequest(S ender as Object, E as EventArgs)
If (Request.Path.IndexOf(chr( 92)) >= 0 OR _
System.IO.Path.GetFullPath (Request.P hysicalPat h) <> 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().GetB aseExcepti on()
strError = strError & "Error Message: " & ErrorInfo.Message.ToString () & vblf & "Error Source: " & ErrorInfo.Source.ToString( ) & vblf & "Error Target Site: " & ErrorInfo.TargetSite.ToStr ing() & vblf & vblf & "QueryString Data:" & vblf & "-----------------" & vblf
' Gathering QueryString information
For i = 0 To Context.Request.QueryStrin g.Count - 1
strError = strError & Context.Request.QueryStrin g.Keys(i) & ":" & vbtab & vbtab & Context.Request.QueryStrin g(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.IsAuthentic ated) then strError = strError & "User:" & vbtab & vbtab & User.Identity.Name & vblf & vblf
strError = strError & "Exception Stack Trace:" & vblf & "----------------------" & vblf & Server.GetLastError.StackT race & vblf & vblf & "Server Variables:" & vblf & "-----------------" & vblf
' Gathering Server Variables information
For i = 0 To Context.Request.ServerVari ables.Coun t - 1
strError = strError & Context.Request.ServerVari ables.Keys (i) & ":" & vbtab & vbtab & Context.Request.ServerVari ables(i) & vblf
Next
strError = strError & vblf
[Code to send emai]
End Sub
</script>
Is there a way I can add to this code the capability to do that?
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Diagnost
<script language="vb" runat="server">
Sub Application_BeginRequest(S
If (Request.Path.IndexOf(chr(
System.IO.Path.GetFullPath
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().GetB
strError = strError & "Error Message: " & ErrorInfo.Message.ToString
' Gathering QueryString information
For i = 0 To Context.Request.QueryStrin
strError = strError & Context.Request.QueryStrin
Next
strError = strError & vblf & "Post Data:" & vblf & "----------" & vblf
' Gathering Post Data information
For i = 0 To Context.Request.Form.Count
strError = strError & Context.Request.Form.Keys(
Next
strError = strError & vblf
if (User.Identity.IsAuthentic
strError = strError & "Exception Stack Trace:" & vblf & "----------------------" & vblf & Server.GetLastError.StackT
' Gathering Server Variables information
For i = 0 To Context.Request.ServerVari
strError = strError & Context.Request.ServerVari
Next
strError = strError & vblf
[Code to send emai]
End Sub
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked- thank you very much
ASKER
strError = strError & vblf ?
strError=strError & System.Environment.Machine
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.