我的App_Themes / Default /文件夹中有两个样式表:BaseStylesheet.css和NonConvert.css
以下是我在示例webform上的代码。我将LastModifiedDate添加到App_Themes文件夹中每个CSS文件的末尾。更新后,LastModifiedDate会自动更新。
Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
'CACHING - Add a LastModifiedDate to all CSS files in the App_Themes directory
Dim link As HtmlLink = Nothing
For Each c As Control In Header.Controls
If TypeOf c Is HtmlLink Then
link = TryCast(c, HtmlLink)
If link.Href.IndexOf("App_Themes/", StringComparison.InvariantCultureIgnoreCase) >= 0 AndAlso link.Href.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase) Then
link.Href += String.Format("?t={0}", GetLastModifiedDateString(link.Href))
End If
End If
Next
End Sub
Public Shared Function GetLastModifiedDateString(ByVal filePath As String) As String
Dim fileInfo As New IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(filePath))
If fileInfo.Exists Then
Return String.Format("{0:yyyyMMddHHmmss}", fileInfo.LastWriteTimeUtc)
End If
Return String.Empty
End Function
这两种方法工作得很好。 html输出如下所示:
<link href="../../App_Themes/Default/BaseStyleSheet.css?t=20140228192910" type="text/css" rel="stylesheet" />
<link href="../../App_Themes/Default/NonConvert.css?t=20140228175530" type="text/css" rel="stylesheet" />
当我添加一个按钮并进行回发时,这是我的html输出:
<link href="../../App_Themes/Default/BaseStyleSheet.css?t=20140228192910" type="text/css" rel="stylesheet" />
<link href="../../App_Themes/Default/BaseStyleSheet.css?t=20140228192910" type="text/css" rel="stylesheet" />
我错过了什么?在viewstate保存之前,我是否必须删除查询字符串?
答案 0 :(得分:0)
我和你有同样的问题。最后我找到了修复它的方法。 也许您可以尝试禁用链接的viewstat,如下所示:
link.EnableViewState = false