Exemplo n.º 1
0
        /// <summary>
        /// return true to put request on hold (until call to Signal()) - return false to allow pipeline to execute immediately
        /// </summary>
        /// <param name="httpApplication"></param>
        /// <returns></returns>
        public static bool DoBeginRequest(HttpApplication httpApplication)
        {
            // use the url as it was requested by the client
            // the real url might be different if it has been translated (proxy, load balancing, ...)
            var url             = ToUrlString(httpApplication.Request);
            var virtualFileCopy = WarmupUtility.EncodeUrl(url.Trim('/'));
            var localCopy       = Path.Combine(HostingEnvironment.MapPath(WarmupFilesPath), virtualFileCopy);

            if (File.Exists(localCopy))
            {
                // result should not be cached, even on proxies
                httpApplication.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
                httpApplication.Response.Cache.SetValidUntilExpires(false);
                httpApplication.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
                httpApplication.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                httpApplication.Response.Cache.SetNoStore();

                httpApplication.Response.WriteFile(localCopy);
                httpApplication.Response.End();
                return(true);
            }

            // there is no local copy and the file exists
            // serve the static file
            if (File.Exists(httpApplication.Request.PhysicalPath))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
 private IAsyncResult BeginBeginRequest(object sender, EventArgs e, AsyncCallback cb, object extradata)
 {
     // host is available, process every requests, or file is processed
     if (!InWarmup() || WarmupUtility.DoBeginRequest(_context))
     {
         var asyncResult = new DoneAsyncResult(extradata);
         cb(asyncResult);
         return(asyncResult);
     }
     else
     {
         // this is the "on hold" execution path
         var asyncResult = new WarmupAsyncResult(cb, extradata);
         Await(asyncResult.Completed);
         return(asyncResult);
     }
 }