title: To force browsers to get latest css in asp.net application
body: <p>To force browsers to get latest css files in asp.net application, I got the following code. But when i used the code CSS is not versioning. Js worked fine with same code. but css shows the file without version like abc.css</p>
  
  <p>I wrote the method in controller and how can I pass to Layout.cshtml in the place of Scripts</p>
  
  <pre><code>public static class JavascriptExtension {
  public static MvcHtmlString IncludeVersionedJs(this HtmlHelper helper, string filename) {
      string version = GetVersion(helper, filename);
      return MvcHtmlString.Create("&lt;script type='text/javascript' src='" + filename + version + "'&gt;&lt;/script&gt;");
  }
  
  private static string GetVersion(this HtmlHelper helper, string filename){
      var context = helper.ViewContext.RequestContext.HttpContext;
      if (context.Cache[filename] == null) {
          var physicalPath = context.Server.MapPath(filename);
          var version = "?v=" +
            new System.IO.FileInfo(physicalPath).LastWriteTime
              .ToString("yyyyMMddhhmmss");
          context.Cache.Add(physicalPath, version, null,
            DateTime.Now.AddMinutes(1), TimeSpan.Zero,
            CacheItemPriority.Normal, null);
          context.Cache[filename] = version;
          return version;
      }
      else {return context.Cache[filename] as string;}
  }
  </code></pre>
  
  <p>Please help</p>