locked
Use ELMAH to Capture User Browser Information / Signal and Error Without Throwing an Exception RRS feed

  • Question

  • User865450124 posted

    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



    Saturday, September 4, 2010 4:45 PM

All replies

  • User-863835478 posted

    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?

    Saturday, September 4, 2010 8:39 PM
  • User865450124 posted

    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


    Saturday, September 4, 2010 11:45 PM