Skip to content

Instantly share code, notes, and snippets.

@tqheel
Created August 20, 2012 21:10
Show Gist options
  • Save tqheel/3407921 to your computer and use it in GitHub Desktop.
Save tqheel/3407921 to your computer and use it in GitHub Desktop.
How to force an ASP.Net application to recompile
//As suggested at http://forums.asp.net/t/1569137.aspx/1
//This is an ugly hack but I needed a way to force the application to recompile on production server.
//Entity Framework was not updating cached values with the latest values from the db
//I tried many other suggested means of fixing this problem to no avail.
//This was a last resort. Has to be done within the context of an httpRequest object
System.IO.FileInfo fi = new System.IO.FileInfo(Server.MapPath("~/Web.config"));
fi.LastWriteTime = DateTime.Now;
//The hack changes the web.config's "last changed" date, which causes ASP.Net to recompile.
//Not pretty, but it works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment