ASP.NET Development Server is not updating changes

2019-04-28 13:07发布

问题:

I've been working on the ASP.NET Development Server recently (on an MVC project and I'm finding that it is inconsistent in how it serves the changes I make to my code. For example, I make a change to the C#/HTML/CSS/JS in the dev environment and run the page, and the change appears on the screen. But if I edit the HTML again and run the page again, the new change doesn't appear. Even ctrl+F5 doesn't do it. I have to stop the web server and run the app again for the changes to update. Has anyone else experienced this? Is there a way to sort this problem out?

If I'm working in IIS and I change something, a ctrl+F5 will always update the page with the changes I've made. I'd like the dev server to be as reliable. Does anyone have any suggestions?

回答1:

Found the answer on this question: caching in asp.net development server



回答2:

Try clearing cache.. on every request

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));

If Still not work. Try this bunch of code in pag load event

Response.AppendHeader("Pragma", "no-cache"); 
Response.AppendHeader("Cache-Control", "no-cache");

Response.CacheControl = "no-cache"; 
Response.Expires = -1;

response.ExpiresAbsolute = new DateTime(1900, 1, 1); 
response.Cache.SetCacheability(HttpCacheability.NoCache);