private void context_BeginRequest(object sender, EventArgs e)
        {
            HttpContext context = ((HttpApplication)sender).Context;

            context.Items["RequestStart"] = DateTime.Now;

            string rawUrl = context.Request.RawUrl;

            log.Info("Starting request for " + rawUrl);
            DateTime startTime = DateTime.Now;

            if (rawUrl.Contains(".aspx"))
            {
                // Rewrite url
                UrlRewriter urlRewriter = new UrlRewriter(context);
                urlRewriter.RewriteUrl(rawUrl);
            }
        }
Exemple #2
0
        //private IWindsorContainer _container;

        #region IHttpHandler Members

        /// <summary>
        /// Process the aspx request. This means (eventually) rewriting the url and registering the page
        /// in the container.
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string rawUrl = context.Request.RawUrl;

            log.Info("Starting request for " + rawUrl);
            DateTime startTime = DateTime.Now;

            // Rewrite url
            UrlRewriter urlRewriter  = new UrlRewriter(context);
            string      rewrittenUrl = urlRewriter.RewriteUrl(rawUrl);

            #region //Ali Ozgur: This is an ajax request, so we have to realign the rewritten url.
            if (context.Request["HTTP_X_MICROSOFTAJAX"] != null)
            {
                int idx = rewrittenUrl.ToLowerInvariant().IndexOf("/default.aspx");
                if (idx >= 0)
                {
                    rewrittenUrl = rewrittenUrl.Substring(idx, rewrittenUrl.Length - idx);
                }
            }
            #endregion

            // Obtain the handler for the current page
            string       aspxPagePath = rewrittenUrl.Substring(0, rewrittenUrl.IndexOf(".aspx") + 5);
            IHttpHandler handler      = PageParser.GetCompiledPageInstance(aspxPagePath, context.Server.MapPath(aspxPagePath), context);

            // Process the page just like any other aspx page
            handler.ProcessRequest(context);

            // Release loaded modules. These modules are added to the HttpContext.Items collection by the ModuleLoader.
            ReleaseModules();

            // Log duration
            TimeSpan duration = DateTime.Now - startTime;
            log.Info(String.Format("Request finshed. Total duration: {0} ms.", duration.Milliseconds));
        }