Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active August 29, 2015 14:09
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 yetanotherchris/9520224dd96dbd0ed7df to your computer and use it in GitHub Desktop.
Save yetanotherchris/9520224dd96dbd0ed7df to your computer and use it in GitHub Desktop.
public static class Extensions
{
public static string GetFingerPrint(this UrlHelper helper)
{
byte[] hash = SHA256.Create().ComputeHash(Encoding.Unicode.GetBytes(GetLastWriteTime()));
return HttpServerUtility.UrlTokenEncode(hash);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string GetLastWriteTime()
{
string binFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin");
return new DirectoryInfo(binFolder).LastWriteTime.ToString();
}
}
// Example usage in an MVC view:
<link type="text/css" href="~/Content/test.less?v=@Url.GetFingerPrint()" rel="stylesheet"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment