Skip to content

Instantly share code, notes, and snippets.

@normansolutions
Last active August 29, 2015 14:03
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 normansolutions/5600e49943d22e5eb5df to your computer and use it in GitHub Desktop.
Save normansolutions/5600e49943d22e5eb5df to your computer and use it in GitHub Desktop.
public static string FingerPrint(string rootRelativePath, string cdnPath = "")
{
if (!string.IsNullOrEmpty(cdnPath) && !HttpContext.Current.IsDebuggingEnabled)
{
return cdnPath;
}
if (HttpRuntime.Cache[rootRelativePath] == null)
{
string relative = VirtualPathUtility.ToAbsolute("~" + rootRelativePath);
string absolute = HostingEnvironment.MapPath(relative);
if (!File.Exists(absolute))
{
throw new FileNotFoundException("File not found", absolute);
}
DateTime date = File.GetLastWriteTime(absolute);
int index = relative.LastIndexOf('/');
string result = relative.Insert(index, "/v-" + date.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