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


C# HttpResponse.CreateCacheDependencyForResponse方法代码示例

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


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

示例1: UpdateFromDependencies

        /*
         * Calculate LastModified and ETag
         * 
         * The LastModified date is the latest last-modified date of 
         * every file that is added as a dependency.
         * 
         * The ETag is generated by concatentating the appdomain id, 
         * filenames and last modified dates of all files into a single string, 
         * then hashing it and Base 64 encoding the hash.
         */
        void UpdateFromDependencies(HttpResponse response) {
            CacheDependency dep = null;
            // if _etag != null && _generateEtagFromFiles == true, then this HttpCachePolicy
            // was created from HttpCachePolicySettings and we don't need to update _etag.
            if (_etag == null && _generateEtagFromFiles) {
                dep = response.CreateCacheDependencyForResponse();
                if (dep == null) {
                    return;
                }
                string id = dep.GetUniqueID();
                if (id == null) {
                    throw new HttpException(SR.GetString(SR.No_UniqueId_Cache_Dependency));
                }
                DateTime utcFileLastModifiedMax = UpdateLastModifiedTimeFromDependency(dep);
                StringBuilder sb = new StringBuilder(256);
                sb.Append(HttpRuntime.AppDomainIdInternal);
                sb.Append(id);
                sb.Append("+LM");
                sb.Append(utcFileLastModifiedMax.Ticks.ToString(CultureInfo.InvariantCulture));
                _etag = Convert.ToBase64String(CryptoUtil.ComputeSHA256Hash(Encoding.UTF8.GetBytes(sb.ToString())));

                //WOS 1540412: if we generate the etag based on file dependencies, encapsulate it within quotes.
                _etag = "\"" + _etag + "\"";
            }

            if (_generateLastModifiedFromFiles) {
                if (dep == null) {
                    dep = response.CreateCacheDependencyForResponse();
                    if (dep == null) {
                        return;
                    }
                }
                DateTime utcFileLastModifiedMax = UpdateLastModifiedTimeFromDependency(dep);
                UtcSetLastModified(utcFileLastModifiedMax);                
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:46,代码来源:HttpCachePolicy.cs


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