Skip to content

Instantly share code, notes, and snippets.

@sucreations
Last active March 21, 2018 22:13
Show Gist options
  • Save sucreations/4731674 to your computer and use it in GitHub Desktop.
Save sucreations/4731674 to your computer and use it in GitHub Desktop.
Reset CSS cache by forcing CSS files to refresh when using ASP.NET Themes
protected override void OnPreRender(System.EventArgs e)
{
//loop through all the controls
foreach (Control oLink in Page.Header.Controls){
if (oLink is HtmlLink){
HtmlLink cssLink = oLink as HtmlLink;
//Check if CSS link
if (cssLink.Attributes["type"].Equals("text/css", StringComparison.CurrentCultureIgnoreCase)){
if (cssLink.Attributes["href"].Contains(String.Format("~/App_Themes/{0}/", Page.Theme))){
//add a version of your app here.
cssLink.Attributes["href"] += "?v.1";
}
}
}
}
base.OnPreRender(e);
}
@Geneticus
Copy link

For active development (change CSS, refresh browser, rinse, repeat), changing that version number to a RNG should clear it every page load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment