Last active
March 21, 2018 22:13
-
-
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
This file contains hidden or 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
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For active development (change CSS, refresh browser, rinse, repeat), changing that version number to a RNG should clear it every page load.