Exemple #1
0
        /// <summary>
        /// 请求被挂起(直到被调用)返回true,直接进入执行返回false
        /// </summary>
        /// <param name="httpApplication"></param>
        /// <returns></returns>
        public static bool DoBeginRequest(HttpApplication httpApplication)
        {
            // 使用客户端访问的地址
            // 真是的地址可能不同,如果客户端使用了代理的话。
            var url             = ToUrlString(httpApplication.Request);
            var virtualFileCopy = WarmupUtility.EncodeUrl(url.Trim('/'));
            var localCopy       = Path.Combine(HostingEnvironment.MapPath(WarmupFilesPath), virtualFileCopy);

            if (File.Exists(localCopy))
            {
                // 不缓存
                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);
            }

            // 存在静态缓存文件
            if (File.Exists(httpApplication.Request.PhysicalPath))
            {
                return(true);
            }

            return(false);
        }
 private IAsyncResult BeginBeginRequest(object sender, EventArgs e, AsyncCallback cb, object extradata)
 {
     // 已经启动,处理请求
     if (!InWarmup() || WarmupUtility.DoBeginRequest(_context))
     {
         var asyncResult = new DoneAsyncResult(extradata);
         cb(asyncResult);
         return(asyncResult);
     }
     else
     {
         // 挂起状态下的执行路径
         var asyncResult = new WarmupAsyncResult(cb, extradata);
         Await(asyncResult.Completed);
         return(asyncResult);
     }
 }