The code below demonstrates how to signal an error in the ELMAH error log without throwing an exception. This specific bit of code captures the browser name and version number that the user utilized to access the site. Given that it is an intranet site that
we're very heavily pushing, we anticipate that we'll finally be able to track down the machines out there that are still running older browsers. We've already upgraded several already. I'm now looking into options that will let us filter out the actual exceptions
from the logged events.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
'Move code here that sets the User Session Variables, currently done in the code behind of DefaultDirectory and the Dashboard Masters
Dim ExceptionMessage As New StringBuilder
ExceptionMessage.Append("Site accessed using " + Request.Browser.Browser + " " + Request.Browser.MajorVersion.toString + "." + Request.Browser.MinorVersion.tostring)
Dim NewException As New NotSupportedException(ExceptionMessage.ToString)
Elmah.ErrorSignal.FromCurrentContext().Raise(NewException)
End Sub
You'll need to get ELMAH up and running. Once its up and running, then it should just be a matter of copying and pasting the code into your global.asax. If you go with a table in SQL Server for the ELMAH logging, be certain that you grant execute permissions
on the ELMAH stored procedures.
dch3
Member
447 Points
638 Posts
Use ELMAH to Capture User Browser Information / Signal and Error Without Throwing an Exception
Sep 04, 2010 08:45 PM|LINK
The code below demonstrates how to signal an error in the ELMAH error log without throwing an exception. This specific bit of code captures the browser name and version number that the user utilized to access the site. Given that it is an intranet site that we're very heavily pushing, we anticipate that we'll finally be able to track down the machines out there that are still running older browsers. We've already upgraded several already. I'm now looking into options that will let us filter out the actual exceptions from the logged events.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started 'Move code here that sets the User Session Variables, currently done in the code behind of DefaultDirectory and the Dashboard Masters Dim ExceptionMessage As New StringBuilder ExceptionMessage.Append("Site accessed using " + Request.Browser.Browser + " " + Request.Browser.MajorVersion.toString + "." + Request.Browser.MinorVersion.tostring) Dim NewException As New NotSupportedException(ExceptionMessage.ToString) Elmah.ErrorSignal.FromCurrentContext().Raise(NewException) End Subthuhue
All-Star
15625 Points
3146 Posts
Re: Use ELMAH to Capture User Browser Information / Signal and Error Without Throwing an Exceptio...
Sep 05, 2010 12:39 AM|LINK
Where and how can we apply what you said?
What do we need to import, install or set reference to?
What do we need to add or change in Web.Config?
dch3
Member
447 Points
638 Posts
Re: Use ELMAH to Capture User Browser Information / Signal and Error Without Throwing an Exceptio...
Sep 05, 2010 03:45 AM|LINK
You'll need to get ELMAH up and running. Once its up and running, then it should just be a matter of copying and pasting the code into your global.asax. If you go with a table in SQL Server for the ELMAH logging, be certain that you grant execute permissions on the ELMAH stored procedures.
http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx