Last active
August 29, 2015 14:09
-
-
Save yetanotherchris/9520224dd96dbd0ed7df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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