Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A fingerprint class for versioning of static web content (derives from Mads Kristensen's Fingerprint class found here http://madskristensen.net/post/cache-busting-in-aspnet)
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
public static class Fingerprint
{
public static string Tag(string rootRelativePath)
{
if (null == HttpRuntime.Cache[rootRelativePath])
{
var absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
var dateLastWrite = File.GetLastWriteTime(absolute);
var result = VirtualPathUtility.ToAbsolute(
string.Format("~{0}?{1}",
rootRelativePath,
dateLastWrite.Ticks));
HttpRuntime.Cache.Insert(
rootRelativePath,
result,
new CacheDependency(absolute));
}
return HttpRuntime.Cache[rootRelativePath] as string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment