本文整理汇总了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);
}
}