6

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?

DaveDev
  • 41,155
  • 72
  • 223
  • 385
  • I'm having the same exact problem Using Visual Studio 2008 with a traditional .net 2.0 webforms based website. Glad I found this question before I asked it again. – NinjaBomb Mar 04 '11 at 18:19
  • 2 of us with the same question and no answers! the solution to-date for me has been to just kill the dev server process when it starts acting up, and restart the application. – DaveDev Mar 04 '11 at 21:20
  • That's what I have been doing. It is slowing me down a lot though and driving me insane because last week it was working. As far as I know, nothing changed on my configuration between then and now. I'm starting to suspect a Windows Update has something to do with it, but that seems a little far fetched. – NinjaBomb Mar 04 '11 at 21:43

1 Answers1

1

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);
  • What's the difference between doing this and a shift+f5 refresh of the page? I've checked the headers of the pages I am requesting and they seem to be completely refeshed each time. Also, to have to add this to each page you are working on, and remembering to take it out before pushing to production, seems cumbersome. – NinjaBomb Mar 05 '11 at 19:22
  • 1
    No not on each page. Just at a single place called Application_BeginRequest event under global.asax.cs file. –  Mar 05 '11 at 21:50
  • Whenever page is refreshed,the web page is cached to your machine. And load the page quicker instead of from server it firsts look into the cache, and if found loads from there. So such thing happens. But in above code when the first time the page is loaded, as in code above first of all it will not create any cache of current request, but if anyhow it creates then its expiration date will be set 1/1/1900 which is already crossed, so the created cache will expire immediately after next request and it will again create a new expiration with same old date.. and so on –  Mar 05 '11 at 21:54
  • I'll give it a try on Monday. It still doesn't explain why asp.net development server is not acting the way it should though and refreshing the pages with our updates. Like I stated above, it was working fine last week. – NinjaBomb Mar 06 '11 at 05:41
  • 1
    Tried the above solution. Didn't work! Still having the same exact problem. – NinjaBomb Mar 07 '11 at 14:15
  • The problem is Dev server is sending old files, it's not the browser caching them... – UpTheCreek Mar 20 '12 at 22:40