当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponse.Compress方法代码示例

本文整理汇总了C#中System.Web.HttpResponse.Compress方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.Compress方法的具体用法?C# HttpResponse.Compress怎么用?C# HttpResponse.Compress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.Compress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequestInner


//.........这里部分代码省略.........
            }

            // Get content
            byte[] page;
            lock (WebCache) {
                // Read cache
                page = WebCache[path] as byte[];

                // If cache miss..
                if (null == page) {

                    // Open WAR file
                    if (null == HttpRoot) {
                        try {
                            HttpRoot = ZipFile.Read(HttpRootFile.FullName);
                        } catch (Exception ex) {
                            // Log the exception
                            LogException(ex, "Variant-HttpRoot", Ids.System);

                            // Warn users that we're updating
                            response.Write("We're currently updating our content. Hang tight - the site will be back shortly!");
                            return;
                        }

                        if (null == HttpRoot["/index.html"]) {
                            throw new Exception("Missing '/index.html' in WAR");
                        }
                    }

                    // Open file
                    ZipEntry file;
                    if (null == (file = HttpRoot[path])) {
                        // File not found - redirect to virtual space

                        response.CacheControl = "public";
                        response.Expires = 31536000;
                        response.ExpiresAbsolute = DateTime.Now.AddYears(1);
                        response.Cache.SetCacheability(HttpCacheability.Public);
                        response.RedirectPermanent("/#!" + path, true);
                        return;
                    }

                    // Extract
                    using (var stream = new MemoryStream()) {
                        file.Extract(stream);
                        page = stream.ReadAllToByteArray();
                    }

                    // Add to cache
                    WebCache[path] = page;
                }
            }

            // Set cache headers
            if (path.Contains(".nocache.")) {
                response.CacheControl = "private";
                response.Expires = 0;
                response.ExpiresAbsolute = DateTime.Now;
                response.Cache.SetCacheability(HttpCacheability.NoCache);
            } else if (path.Contains(".cache.")) {
                response.CacheControl = "public";
                response.Expires = 365 * 24 * 60 * 60;
                response.ExpiresAbsolute = DateTime.Now.AddDays(365);
                response.Cache.SetCacheability(HttpCacheability.Public);
            } else {
                response.CacheControl = "private";
                response.Expires = 1 * 24 * 60 * 60;
                response.ExpiresAbsolute = DateTime.Now.AddDays(1);
                response.Cache.SetCacheability(HttpCacheability.Private);
            }

            // Set content type
            switch (Path.GetExtension(path).ToUpperInvariant()) {
                case ".JS":
                    response.ContentType = "text/javascript";
                    break;
                case ".JSON":
                    response.ContentType = "application/json";
                    break;
                case ".CSS":
                    response.ContentType = "text/css";
                    break;
                case ".JPG":
                case ".JPEG":
                    response.ContentType = "image/jpeg";
                    break;
                case ".PNG":
                    response.ContentType = "image/png";
                    break;
                case ".GIF":
                    response.ContentType = "image/gif";
                    break;
            }

            // Set compression
            response.Compress(request);

            // Write
            response.OutputStream.Write(page, 0, page.Length);
        }
开发者ID:invertedtomato,项目名称:Amos3,代码行数:101,代码来源:Variant.cs


注:本文中的System.Web.HttpResponse.Compress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。