Can I force a refresh of my stylesheet file?

前端 未结 12 2204
-上瘾入骨i
-上瘾入骨i 2020-12-13 18:51

I have just spent half a day quietly going mad.

I\'m making changes to my classes in the Site.css file and they were not being reflected in the site being develope

12条回答
  •  执笔经年
    2020-12-13 19:33

    For ASP.NET, the code behind (you can put this in a utility class or master page):

    public static string GetTimestampedUrl(string virtualPath)
    {
      var realPath = HostingEnvironment.MapPath(virtualPath);
      var file = new FileInfo(realPath);
    
      return VirtualPathUtility.ToAbsolute(virtualPath) + "?" + file.LastWriteTime.ToFileTime();
    }
    

    And then in your page:

    " rel="stylesheet" type="text/css" media="screen" />
    

提交回复
热议问题