/// <summary>
 /// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule"/>.
 /// </summary>
 public void Dispose()
 {
     try
     {
         if (m_CurrentRequestMetric != null)
         {
             m_CurrentRequestMetric.Suppress();
             m_CurrentRequestMetric.Dispose();
             m_CurrentRequestMetric = null;
         }
     }
     catch
     {}
 }
        private void HttpApplicationBeginRequest(object sender, EventArgs e)
        {
            //we could have a current request - if the last request aborted or ended early.
            if (m_CurrentRequestMetric != null)
            {
                //but we aren't going to consider its timing valid because who knows how long it sat in the queue.
                m_CurrentRequestMetric.Suppress();
                m_CurrentRequestMetric.Dispose();
            }

            //create a new metric.  We then go configure it, but we may set it back to null if this is an image or something.
            m_CurrentRequestMetric = new HttpRequestMetric();

            try
            {

                HttpApplication application = sender as HttpApplication;
                Debug.Assert(application != null);

                //figure out the page and the full path in our friendly form.
                HttpRequest request = application.Request;
                string fullAppRelativePath = request.AppRelativeCurrentExecutionFilePath;

                if (string.IsNullOrEmpty(fullAppRelativePath) == false)
                {

                    //but pull off the ~/ to get rid of silliness
                    if (fullAppRelativePath.StartsWith("~/"))
                    {
                        fullAppRelativePath = fullAppRelativePath.Substring(2);
                    }

                    m_CurrentRequestMetric.AbsolutePath = fullAppRelativePath;

                    //now see if we can find just the file name.
                    int fileStartIndex = fullAppRelativePath.LastIndexOfAny(Delimiters);
                    if (fileStartIndex == -1)
                        fileStartIndex = 0; //we never found a slash, so we start at zero.
                    else
                        fileStartIndex++; //because we don't really want the slash.

                    //and we don't want any extension for this pretty name...
                    int extensionIndex = fullAppRelativePath.IndexOf('.', fileStartIndex);
                    if (extensionIndex == -1)
                        extensionIndex = fullAppRelativePath.Length - 1; //so we go to the end.

                    int nameLength = (extensionIndex - fileStartIndex);
                    m_CurrentRequestMetric.PageName = (nameLength  > 0) ? fullAppRelativePath.Substring(fileStartIndex, (extensionIndex - fileStartIndex)) : string.Empty;

                    m_CurrentRequestMetric.QueryString = request.Url.Query;

                    //and get the extension as well, so we can decide if we even care about this guy.
                    if (extensionIndex < (fullAppRelativePath.Length - 1))
                    {
                        string extension = fullAppRelativePath.Substring(extensionIndex + 1); //add the one to get rid of the period.

                        if ((string.IsNullOrEmpty(extension) == false) && (IsExcludedExtension(extension.ToLowerInvariant())))
                            m_CurrentRequestMetric = null; //so we don't record jack.
                    }

                    //careful!  at this point the current request may be null
                }
            }
            catch (Exception ex)
            {
                GC.KeepAlive(ex);

#if DEBUG
                Log.RecordException(ex, "System", true);
#endif
            }
        }
 private void HttpApplicationEndRequest(object sender, EventArgs e)
 {
     if (m_CurrentRequestMetric != null)
     {
         //dispose the metric to have it record itself and then clear our pointer.
         m_CurrentRequestMetric.Dispose();
         m_CurrentRequestMetric = null;
     }
 }
        private void HttpApplicationEndRequest(object sender, EventArgs e)
        {
            if (m_CurrentRequestMetric != null)
            {
                if (HttpContext.Current != null)
                {
                    if (HttpContext.Current.User != null)
                    {
                        m_CurrentRequestMetric.UserName = HttpContext.Current.User.Identity.Name;
                    }

                    m_CurrentRequestMetric.SessionId = HttpContext.Current.Items["LoupeSessionId"] as string;
                    m_CurrentRequestMetric.AgentSessionId = HttpContext.Current.Items["LoupeAgentSessionId"] as string;
                }

                //dispose the metric to have it record itself and then clear our pointer.
                m_CurrentRequestMetric.Dispose();
                m_CurrentRequestMetric = null;
            }
        }