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


C# HttpContextBase.AddCompressionResponseHeader方法代码示例

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


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

示例1: PerformCompression

        internal static void PerformCompression(HttpContextBase context)
        {
            var cType = context.GetClientCompression();
            context.AddCompressionResponseHeader(cType);

            if (cType == CompressionType.deflate)
            {
                context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress);
            }
            else if (cType == CompressionType.gzip)
            {
                context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
            }
        }
开发者ID:ElijahGlover,项目名称:ClientDependency,代码行数:14,代码来源:MimeTypeCompressor.cs

示例2: ProcessFromFile

 private void ProcessFromFile(HttpContextBase context, CompositeFileMap map, out string compositeFileName, out byte[] outputBytes)
 {
     //the saved file's bytes are already compressed.
     outputBytes = map.GetCompositeFileBytes();
     compositeFileName = map.CompositeFileName;
     var cType = (CompressionType)Enum.Parse(typeof(CompressionType), map.CompressionType);
     context.AddCompressionResponseHeader(cType);
 }
开发者ID:dufkaf,项目名称:ClientDependency,代码行数:8,代码来源:CompositeDependencyHandler.cs

示例3: ProcessRequestInternal

        internal byte[] ProcessRequestInternal(HttpContextBase context, string fileset, ClientDependencyType type, int version, byte[] outputBytes, OutputCachedPage page)
        {
            //get the compression type supported
            var clientCompression = context.GetClientCompression();

			var x1 = ClientDependencySettings.Instance;
			if (x1 == null) throw new Exception("x1");
			var x2 = x1.DefaultFileMapProvider;
			if (x2 == null) throw new Exception("x2");

            //get the map to the composite file for this file set, if it exists.
            var map = ClientDependencySettings.Instance.DefaultFileMapProvider.GetCompositeFile(fileset, version, clientCompression.ToString());

            string compositeFileName = "";
            if (map != null && map.HasFileBytes)
            {
                ProcessFromFile(context, map, out compositeFileName, out outputBytes);
            }
            else
            {
                lock (Lock)
                {
                    //check again...
                    if (map != null && map.HasFileBytes)
                    {
                        //there's files there now, so process them
                        ProcessFromFile(context, map, out compositeFileName, out outputBytes);
                    }
                    else
                    {
                        List<CompositeFileDefinition> fileDefinitions;
                        byte[] fileBytes;

                        if (ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.UrlType == CompositeUrlType.MappedId)
                        {
                            //need to try to find the map by it's id/version (not compression)
                            var filePaths = ClientDependencySettings.Instance.DefaultFileMapProvider.GetDependentFiles(fileset, version);

                            if (filePaths == null)
                            {
                                throw new KeyNotFoundException("no map was found for the dependency key: " + fileset +
                                                               " ,CompositeUrlType.MappedId requires that a map is found");
                            }

                            //combine files and get the definition types of them (internal vs external resources)
                            fileBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider
                                .CombineFiles(filePaths.ToArray(), context, type, out fileDefinitions);
                        }
                        else
                        {
                            //need to do the combining, etc... and save the file map                            
                            fileBytes = GetCombinedFiles(context, fileset, type, out fileDefinitions);                           
                        }

                        //compress data                        
                        outputBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.CompressBytes(clientCompression, fileBytes);
                        context.AddCompressionResponseHeader(clientCompression);

                        //save combined file
                        var compositeFile = ClientDependencySettings.Instance
                            .DefaultCompositeFileProcessingProvider
                            .SaveCompositeFile(outputBytes, type, context.Server);

                        if (compositeFile != null)
                        {
                            compositeFileName = compositeFile.FullName;
                            if (!string.IsNullOrEmpty(compositeFileName))
                            {
                                //Update the XML file map
                                ClientDependencySettings.Instance.DefaultFileMapProvider.CreateUpdateMap(fileset, clientCompression.ToString(),
                                    fileDefinitions.Select(x => new BasicFile(type) { FilePath = x.Uri }),
                                        compositeFileName,
                                        //TODO: We should probably use the passed in version param?
                                        ClientDependencySettings.Instance.Version);
                            }
                        }
                    }
                }
            }
            
            //set our caching params 
            SetCaching(context, compositeFileName, fileset, clientCompression, page);

            return outputBytes;
        }
开发者ID:dufkaf,项目名称:ClientDependency,代码行数:85,代码来源:CompositeDependencyHandler.cs

示例4: ProcessRequestInternal

        internal byte[] ProcessRequestInternal(HttpContextBase context, string fileset, ClientDependencyType type, int version, byte[] outputBytes)
        {
            //get the compression type supported
            CompressionType cType = context.GetClientCompression();

            //get the map to the composite file for this file set, if it exists.
            CompositeFileMap map = CompositeFileXmlMapper.Instance.GetCompositeFile(fileset, version, cType.ToString());

            string compositeFileName = "";
            if (map != null && map.HasFileBytes)
            {
                ProcessFromFile(context, map, out compositeFileName, out outputBytes);
            }
            else
            {
                bool fromFile = false;

                lock (m_Lock)
                {
                    //check again...
                    if (map == null || !map.HasFileBytes)
                    {
                        //need to do the combining, etc... and save the file map

                        List<CompositeFileDefinition> fDefs;
                        byte[] fileBytes = GetCombinedFiles(context, fileset, type, out fDefs);
                        //compress data
                        outputBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.CompressBytes(cType, fileBytes);
                        context.AddCompressionResponseHeader(cType);
                        //save combined file
                        FileInfo compositeFile = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.SaveCompositeFile(outputBytes, type, context.Server);
                        if (compositeFile != null)
                        {
                            compositeFileName = compositeFile.FullName;
                            if (!string.IsNullOrEmpty(compositeFileName))
                            {
                                //Update the XML file map
                                CompositeFileXmlMapper.Instance.CreateMap(fileset, cType.ToString(),
                                    fDefs
                                        .Where(f => f.IsLocalFile)
                                        .Select(x => new FileInfo(context.Server.MapPath(x.Uri))).ToList(), compositeFileName,
                                        ClientDependencySettings.Instance.Version);
                            }
                        }
                    }
                    else
                    {
                        //files are there now, process from file.
                        fromFile = true;
                    }
                }

                if (fromFile)
                {
                    ProcessFromFile(context, map, out compositeFileName, out outputBytes);
                }
            }

            SetCaching(context, compositeFileName);
            return outputBytes;
        }
开发者ID:aozora,项目名称:arashi,代码行数:61,代码来源:CompositeDependencyHandler.cs


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