Skip to content

Instantly share code, notes, and snippets.

@vkocjancic
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkocjancic/1140979eea08a8b00b5f to your computer and use it in GitHub Desktop.
Save vkocjancic/1140979eea08a8b00b5f to your computer and use it in GitHub Desktop.
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