473,412 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Application_error and windows 2003

I have a problem with the application_error event being fired from my
asp.net application with windows 2003 server standard edition. The
event fires fine from my test machine (XP) and all works well. However
the event never appears to fire from windows 2003. I have tried just
about everything and can not find an answer. I cannot debug through the
windows 2003 server as I do not have VS installed on it plus it is a
live server

Can any one help?
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim LastError As Exception = Server.GetLastError
ErrorHandler.ExceptionToString(LastError)
Server.ClearError()
Response.Redirect("~/Error.html")
End Sub

Nov 19 '05 #1
6 1418
Hi,

Are you trying to test the exception management code of your app in ur
Win2k3 server? In other words, are you purposefully thowing an exception to
see whether it's handled properly?

If yes, how exactly are you doing that?

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"Rippo" wrote:
I have a problem with the application_error event being fired from my
asp.net application with windows 2003 server standard edition. The
event fires fine from my test machine (XP) and all works well. However
the event never appears to fire from windows 2003. I have tried just
about everything and can not find an answer. I cannot debug through the
windows 2003 server as I do not have VS installed on it plus it is a
live server

Can any one help?
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim LastError As Exception = Server.GetLastError
ErrorHandler.ExceptionToString(LastError)
Server.ClearError()
Response.Redirect("~/Error.html")
End Sub

Nov 19 '05 #2
Yes. I am purposefully throwing an exception. Like my original post
says I can get the error to display on XP but not on Windows 2003.

I have had a further thought and may think that this may be a
permission issue. The server in question is running the Ensim control
panel and it does stuff with user accounts that locks down IIS pretty
well. So for a check what group does the IIS user need to allow for
application_error to be fired?

At the moment the user is w#21 and groups are AllUsers@n2cb, iis_wpg
and wvh_anon_users_group

Nov 19 '05 #3
Hi,

I don't think permissions plat a role in application_error. My hunch is
there should be a permission problem in what is being done within the
application_error handler. And maybe that is the reason why it seems like the
error event is not firing.

Could you please post the code written in application_error?

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"Rippo" wrote:
Yes. I am purposefully throwing an exception. Like my original post
says I can get the error to display on XP but not on Windows 2003.

I have had a further thought and may think that this may be a
permission issue. The server in question is running the Ensim control
panel and it does stuff with user accounts that locks down IIS pretty
well. So for a check what group does the IIS user need to allow for
application_error to be fired?

At the moment the user is w#21 and groups are AllUsers@n2cb, iis_wpg
and wvh_anon_users_group

Nov 19 '05 #4
You could be right. I have set the full control permissions for the
asp_net account in reg edit for the event log WriteToEventLog function.
May be it is that that is causing the problem. I will write some code
to see.

Code below in case it could be something else

in web.config
<!-- CUSTOM ERROR MESSAGES -->
<customErrors mode="On" defaultRedirect="~/Error.aspx" >
<error statusCode="404" redirect="~/"/>
</customErrors>
in globbal
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim LastError As Exception = Server.GetLastError
ErrorHandler.ExceptionToString(LastError)
Server.ClearError()
Response.Redirect("~/Error.html")
End Sub
------------------------------------------------
ErrorHandler.vb

Imports System.Reflection
Imports System.Text.RegularExpressions
Imports System.Xml
Imports System.Web
Imports System.Configuration
Imports System.Web.HttpContext
Imports System.Diagnostics
Namespace codetools

Public Class ErrorHandler
Private Const m_strRootException As String =
"System.Web.HttpUnhandledException"
Public Sub ExceptionToString(ByVal ex As Exception)
Dim sb As New System.Text.StringBuilder

With sb
.Append(ex.ToString)
.Append(ExceptionToStringPrivate(ex))
' get ASP specific settings
Try
.Append(GetASPSettings())
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)
End With

'HttpContext.Current.Response.Write(sb.ToString)

WriteToEventLog(sb.ToString, "N2C", EventLogEntryType.Error, "N2C")

End Sub

Private Function WriteToEventLog(ByVal Entry As String, _
Optional ByVal AppName As String = "VB.NET Application", _
Optional ByVal EventType As _
EventLogEntryType = EventLogEntryType.Information, _
Optional ByVal LogName As String = "Application") As Boolean

'************************************************* ************
'PURPOSE: Write Entry to Event Log using VB.NET
'PARAMETERS: Entry - Value to Write
' AppName - Name of Client Application. Needed
' because before writing to event log, you must
' have a named EventLog source.
' EventType - Entry Type, from EventLogEntryType
' Structure e.g., EventLogEntryType.Warning,
' EventLogEntryType.Error
' LogName: Name of Log (System, Application;
' Security is read-only) If you
' specify a non-existent log, the log will be
' created

'RETURNS: True if successful, false if not

'EXAMPLES:
'1. Simple Example, Accepting All Defaults
' WriteToEventLog "Hello Event Log"

'2. Specify EventSource, EventType, and LogName
' WriteToEventLog("Danger, Danger, Danger", "MyVbApp", _
' EventLogEntryType.Warning, "System")
'
'NOTE: EventSources are tightly tied to their log.
' So don't use the same source name for different
' logs, and vice versa
'************************************************* *****

Dim objEventLog As New EventLog

Try
'Register the App as an Event Source
If Not objEventLog.SourceExists(AppName) Then

objEventLog.CreateEventSource(AppName, LogName)
End If

objEventLog.Source = AppName

'WriteEntry is overloaded; this is one
'of 10 ways to call it
objEventLog.WriteEntry(Entry, EventType)
Return True
Catch Ex As Exception
Return False

End Try

End Function
Private Function ExceptionToStringPrivate(ByVal ex As Exception, _
Optional ByVal blnIncludeSysInfo As Boolean = True) As String

Dim sb As New System.Text.StringBuilder

If Not (ex.InnerException Is Nothing) Then

' sometimes the original exception is wrapped in a more relevant
outer exception
' the detail exception is the "inner" exception
' see
http://msdn.microsoft.com/library/de...ceptdotnet.asp
' don't return the outer root ASP exception; it is redundant.
If ex.GetType.ToString = m_strRootException Then
Return ExceptionToStringPrivate(ex.InnerException)
Else
With sb
.Append(ExceptionToStringPrivate(ex.InnerException , False))
.Append(Environment.NewLine)
.Append("(Outer Exception)")
.Append(Environment.NewLine)
End With
End If
End If

With sb
' get exception-specific information

.Append("Exception Type: ")
Try
.Append(ex.GetType.FullName)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)

.Append("Exception Message: ")
Try
.Append(ex.Message)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)

.Append("Exception Source: ")
Try
.Append(ex.Source)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)

.Append("Exception Target Site: ")
Try
.Append(ex.TargetSite.Name)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)
End With

Return sb.ToString

End Function

Private Function GetASPSettings() As String

Dim sb As New System.Text.StringBuilder

With sb
.Append("---- Collections ----")
.Append(Environment.NewLine)
.Append(Environment.NewLine)
.Append(GetHttpVars(System.Web.HttpContext.Current .Request.QueryString,
"QueryString"))
.Append(GetHttpVars(System.Web.HttpContext.Current .Request.Form,
"Form"))
.Append(GetHttpCookieVars)
.Append(GetHttpVars(System.Web.HttpContext.Current .Request.ServerVariables,
"ServerVariables", True, "^ALL_HTTP|^ALL_RAW"))
End With

Return sb.ToString

End Function

Private Function GetHttpVars(ByVal NameValueCollection As
Specialized.NameValueCollection, ByVal strTitle As String, _
Optional ByVal blnSuppressEmptyValues As Boolean = False, _
Optional ByVal strSuppressKeyRegex As String = "") As String

' do we have data in the collection?
If Not NameValueCollection.HasKeys Then Return ""

' if so format the data
Dim sb As New System.Text.StringBuilder
sb.Append(strTitle)
sb.Append(Environment.NewLine)
sb.Append(Environment.NewLine)

Dim blnDisplay As Boolean
Dim strItem As String

' loop through each item in the name value collection
For Each strItem In NameValueCollection
blnDisplay = True

' if we need to suppress empty values set display flag based on if
we have data
If blnSuppressEmptyValues Then
blnDisplay = NameValueCollection(strItem) <> String.Empty
End If

' check to see if our regex does not match
If blnDisplay AndAlso strSuppressKeyRegex <> String.Empty Then
blnDisplay = Not Regex.IsMatch(strItem, strSuppressKeyRegex)
End If

' if conditions where met render item
If blnDisplay Then
AppendLine(sb, strItem, NameValueCollection(strItem))
End If

Next

sb.Append(Environment.NewLine)
Return sb.ToString

End Function

Private Function AppendLine(ByVal sb As System.Text.StringBuilder, _
ByVal strKey As String, ByVal strValue As String) As String

sb.Append(String.Format(" {0, -30}{1}", strKey, strValue))
sb.Append(Environment.NewLine)

End Function

Private Function GetHttpCookieVars() As String

' do we have cookies?
If System.Web.HttpContext.Current.Request.Cookies.Cou nt = 0 Then
Return ""

' build formatted cookie information
Dim sb As New System.Text.StringBuilder
sb.Append("Cookies")
sb.Append(Environment.NewLine)
sb.Append(Environment.NewLine)
Dim strItem As String
For Each strItem In System.Web.HttpContext.Current.Request.Cookies
AppendLine(sb, strItem,
System.Web.HttpContext.Current.Request.Cookies(str Item).Value)
Next

sb.Append(Environment.NewLine)
Return sb.ToString

End Function

Private Function ProcessIdentity() As String
Dim strTemp As String
strTemp = CurrentWindowsIdentity()
If strTemp = "" Then
strTemp = CurrentEnvironmentIdentity()
End If
Return strTemp
End Function

Private Function CurrentWindowsIdentity() As String
Try
Return System.Security.Principal.WindowsIdentity.GetCurre nt.Name()
Catch ex As Exception
Return ""
End Try
End Function

Private Function CurrentEnvironmentIdentity() As String
Try
Return System.Environment.UserDomainName + "\" +
System.Environment.UserName
Catch ex As Exception
Return ""
End Try
End Function
Private Function WebCurrentUrl() As String
Dim strUrl As String
With System.Web.HttpContext.Current.Request.ServerVaria bles
strUrl = "http://" & .Item("server_name")
If .Item("server_port") <> "80" Then
strUrl &= ":" & .Item("server_port")
End If
strUrl &= .Item("url")
If .Item("query_string").Length > 0 Then
strUrl &= "?" & .Item("query_string")
End If
End With
Return strUrl
End Function
End Class
End Namespace

Nov 19 '05 #5
Hi,

I am going thru the code.

Meanwhile, one question - are you using impersonation? If yes, then you need
to provide the impersonated user the rights instead of the ASPNET user.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"Rippo" wrote:
You could be right. I have set the full control permissions for the
asp_net account in reg edit for the event log WriteToEventLog function.
May be it is that that is causing the problem. I will write some code
to see.

Code below in case it could be something else

in web.config
<!-- CUSTOM ERROR MESSAGES -->
<customErrors mode="On" defaultRedirect="~/Error.aspx" >
<error statusCode="404" redirect="~/"/>
</customErrors>
in globbal
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim LastError As Exception = Server.GetLastError
ErrorHandler.ExceptionToString(LastError)
Server.ClearError()
Response.Redirect("~/Error.html")
End Sub
------------------------------------------------
ErrorHandler.vb

Imports System.Reflection
Imports System.Text.RegularExpressions
Imports System.Xml
Imports System.Web
Imports System.Configuration
Imports System.Web.HttpContext
Imports System.Diagnostics
Namespace codetools

Public Class ErrorHandler
Private Const m_strRootException As String =
"System.Web.HttpUnhandledException"
Public Sub ExceptionToString(ByVal ex As Exception)
Dim sb As New System.Text.StringBuilder

With sb
.Append(ex.ToString)
.Append(ExceptionToStringPrivate(ex))
' get ASP specific settings
Try
.Append(GetASPSettings())
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)
End With

'HttpContext.Current.Response.Write(sb.ToString)

WriteToEventLog(sb.ToString, "N2C", EventLogEntryType.Error, "N2C")

End Sub

Private Function WriteToEventLog(ByVal Entry As String, _
Optional ByVal AppName As String = "VB.NET Application", _
Optional ByVal EventType As _
EventLogEntryType = EventLogEntryType.Information, _
Optional ByVal LogName As String = "Application") As Boolean

'************************************************* ************
'PURPOSE: Write Entry to Event Log using VB.NET
'PARAMETERS: Entry - Value to Write
' AppName - Name of Client Application. Needed
' because before writing to event log, you must
' have a named EventLog source.
' EventType - Entry Type, from EventLogEntryType
' Structure e.g., EventLogEntryType.Warning,
' EventLogEntryType.Error
' LogName: Name of Log (System, Application;
' Security is read-only) If you
' specify a non-existent log, the log will be
' created

'RETURNS: True if successful, false if not

'EXAMPLES:
'1. Simple Example, Accepting All Defaults
' WriteToEventLog "Hello Event Log"

'2. Specify EventSource, EventType, and LogName
' WriteToEventLog("Danger, Danger, Danger", "MyVbApp", _
' EventLogEntryType.Warning, "System")
'
'NOTE: EventSources are tightly tied to their log.
' So don't use the same source name for different
' logs, and vice versa
'************************************************* *****

Dim objEventLog As New EventLog

Try
'Register the App as an Event Source
If Not objEventLog.SourceExists(AppName) Then

objEventLog.CreateEventSource(AppName, LogName)
End If

objEventLog.Source = AppName

'WriteEntry is overloaded; this is one
'of 10 ways to call it
objEventLog.WriteEntry(Entry, EventType)
Return True
Catch Ex As Exception
Return False

End Try

End Function
Private Function ExceptionToStringPrivate(ByVal ex As Exception, _
Optional ByVal blnIncludeSysInfo As Boolean = True) As String

Dim sb As New System.Text.StringBuilder

If Not (ex.InnerException Is Nothing) Then

' sometimes the original exception is wrapped in a more relevant
outer exception
' the detail exception is the "inner" exception
' see
http://msdn.microsoft.com/library/de...ceptdotnet.asp
' don't return the outer root ASP exception; it is redundant.
If ex.GetType.ToString = m_strRootException Then
Return ExceptionToStringPrivate(ex.InnerException)
Else
With sb
.Append(ExceptionToStringPrivate(ex.InnerException , False))
.Append(Environment.NewLine)
.Append("(Outer Exception)")
.Append(Environment.NewLine)
End With
End If
End If

With sb
' get exception-specific information

.Append("Exception Type: ")
Try
.Append(ex.GetType.FullName)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)

.Append("Exception Message: ")
Try
.Append(ex.Message)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)

.Append("Exception Source: ")
Try
.Append(ex.Source)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)

.Append("Exception Target Site: ")
Try
.Append(ex.TargetSite.Name)
Catch e As Exception
.Append(e.Message)
End Try
.Append(Environment.NewLine)
End With

Return sb.ToString

End Function

Private Function GetASPSettings() As String

Dim sb As New System.Text.StringBuilder

With sb
.Append("---- Collections ----")
.Append(Environment.NewLine)
.Append(Environment.NewLine)
.Append(GetHttpVars(System.Web.HttpContext.Current .Request.QueryString,
"QueryString"))
.Append(GetHttpVars(System.Web.HttpContext.Current .Request.Form,
"Form"))
.Append(GetHttpCookieVars)
.Append(GetHttpVars(System.Web.HttpContext.Current .Request.ServerVariables,
"ServerVariables", True, "^ALL_HTTP|^ALL_RAW"))
End With

Return sb.ToString

End Function

Private Function GetHttpVars(ByVal NameValueCollection As
Specialized.NameValueCollection, ByVal strTitle As String, _
Optional ByVal blnSuppressEmptyValues As Boolean = False, _
Optional ByVal strSuppressKeyRegex As String = "") As String

' do we have data in the collection?
If Not NameValueCollection.HasKeys Then Return ""

' if so format the data
Dim sb As New System.Text.StringBuilder
sb.Append(strTitle)
sb.Append(Environment.NewLine)
sb.Append(Environment.NewLine)

Dim blnDisplay As Boolean
Dim strItem As String

' loop through each item in the name value collection
For Each strItem In NameValueCollection
blnDisplay = True

' if we need to suppress empty values set display flag based on if
we have data
If blnSuppressEmptyValues Then
blnDisplay = NameValueCollection(strItem) <> String.Empty
End If

' check to see if our regex does not match
If blnDisplay AndAlso strSuppressKeyRegex <> String.Empty Then
blnDisplay = Not Regex.IsMatch(strItem, strSuppressKeyRegex)
End If

' if conditions where met render item
If blnDisplay Then
AppendLine(sb, strItem, NameValueCollection(strItem))
End If

Next

sb.Append(Environment.NewLine)
Return sb.ToString

End Function

Private Function AppendLine(ByVal sb As System.Text.StringBuilder, _
ByVal strKey As String, ByVal strValue As String) As String

sb.Append(String.Format(" {0, -30}{1}", strKey, strValue))
sb.Append(Environment.NewLine)

End Function

Private Function GetHttpCookieVars() As String

' do we have cookies?
If System.Web.HttpContext.Current.Request.Cookies.Cou nt = 0 Then
Return ""

' build formatted cookie information
Dim sb As New System.Text.StringBuilder
sb.Append("Cookies")
sb.Append(Environment.NewLine)
sb.Append(Environment.NewLine)
Dim strItem As String
For Each strItem In System.Web.HttpContext.Current.Request.Cookies
AppendLine(sb, strItem,
System.Web.HttpContext.Current.Request.Cookies(str Item).Value)
Next

sb.Append(Environment.NewLine)
Return sb.ToString

End Function

Private Function ProcessIdentity() As String
Dim strTemp As String
strTemp = CurrentWindowsIdentity()
If strTemp = "" Then
strTemp = CurrentEnvironmentIdentity()
End If
Return strTemp
End Function

Private Function CurrentWindowsIdentity() As String
Try

Nov 19 '05 #6
No i am not using impersonation.

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Greg Burns | last post by:
I am trying to write a global custom error page. I thought I would jot down some of what I've learned so far... At first I just used the default customErrors section with a defaultRedirect tag,...
3
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a...
0
by: Michael | last post by:
Hi, I have an ASP.NET application that catches un-handled exceptions in the Application_Error method and writes the details to the Event Log. But, if I do a Server.ClearError() followed by either...
0
by: Michael | last post by:
Hi, I have an ASP.NET application that catches un-handled exceptions in the Application_Error method and writes the details to the Event Log. But, if I do a Server.ClearError() followed by either...
4
by: Chris Leffer | last post by:
Hi. I have the following code in my Global.asax Application_error event: Dim lgEntryLog As New Logs.Custom Dim exApp As Exception = Server.GetLastError.GetBaseException Try With lgEntryLog...
6
by: Matt | last post by:
Can anyone give me a good reason to use BOTH application scope Page_Error and the page scope Page_Error when trapping errors in a web application? Is there any real benefit to using the Page_Error...
1
by: David Herbst | last post by:
VS 2005 / .NET 2.0 Windows 2000 Server sp4 (on development as well as testing server) Using Web Deployment Project to build assemblies for testing and production servers. I added a Global.asax...
0
by: Brian | last post by:
Greetings group! I've got a weird one. I have an ASP.NET 1.1 application that has been running on a dual-processor Windows 2000/IIS 5 server for a couple of years. Global.asax has an...
19
by: =?Utf-8?B?anZjb2FjaDIz?= | last post by:
I've got a global.aspx file that works in my dev environment (vs 2005). When i publish the site to a windows 2000 sp4 box running IIS, the global does not seem to fire. Since it's a test server,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.