13

Scenario: I have an ASP.NET MVC application developed in Visual Studio 2008. There is a root folder named "Content" that stores images and stylesheets. When I run locally (using Cassini) and browse my application, every resource from the "Content" directory is always downloaded. Using Firebug, I can verify that the web server returns an HTTP 200 ("ok").

Desired: I would like for Cassini to return HTTP 304 ("not modified") instead of 200. This is the behavior when running the site under IIS7.

Reasoning: The site I am working on has a large number of static resources (often as many as 40 per page). Browsing the site is very fast on IIS7, because these resources are (correctly) cached by the browser. However, browsing the site on my local machine is painfully slow.

Pages that render in under 1 second on IIS7 take over 30 seconds to render on Cassini. It's actually faster for me to upload the entire website every few minutes and test from there. (Yes, I recognize that this is perverse and crazy.)

So: how can I instruct/trick Cassini into treating the "Content" directory like IIS7 does?

Portman
  • 30,925
  • 24
  • 79
  • 101

3 Answers3

27

Are you sure the problem is caching? Because the content does get cached correctly on my machine when I run the application on Cassini.

I think the problem you're having could be Firefox's under-performance with resolving IPv6 addresses, which causes a very annoying delay on loads with addresses like http://localhost:55555.

What I did to change this behaviour was to change the network.dns.disableIPv6 preference on about:config to true on Firefox. I suggest trying that.

Çağdaş Tekin
  • 16,322
  • 4
  • 46
  • 58
  • 1
    Holy crap you're a genius! I made that change and now the results are 304s, as expected. The problem *is* caching however... when network.dns.disableIPv6 is set to false, Firefox does not send the "if-match" HTTP request headers to localhost. Wierd! – Portman Apr 27 '09 at 22:20
  • :) I'm glad that did the trick. That's a really annoying problem indeed. – Çağdaş Tekin Apr 27 '09 at 22:23
  • Ditto on the genius. Thanks for this answer. – womp Jul 05 '09 at 05:46
  • 1
    O. M. G. With this one answer you have magically granted me back hours in lost development time. WOW. Thank you! Never would have figure this out in a thousand years. – Dave Markle Nov 14 '09 at 19:16
  • OMFG! I thought this was just because the dev web server was slow... Holy crap this is fast now. I can't believe I accepted this for so long. Yikes. – WildJoe May 30 '10 at 08:18
  • THANK YOU! This has been driving me BATTY! The difference with a lot of resources is simply staggering. – jhappoldt Nov 22 '10 at 21:07
  • Thanks! Worked for me too. However, the same problem occurs in Chrome. Is there similar parameter to tweak? – UserControl Dec 09 '10 at 12:54
  • @UserControl, I don't know about the Chrome unfortunately. – Çağdaş Tekin Dec 09 '10 at 14:30
15

I've had a similar problem in Chrome. To resolve this uncomment the IPv4 localhost line in you hosts file. Apparently these are commented by default in Windows 7.

127.0.0.1       localhost
#::1             localhost
Robert Massa
  • 3,905
  • 1
  • 27
  • 44
2

Another option for you is to simply skip Cassini and debug under IIS. It's pretty straightforward, and won't take you ten minutes to get up and running. Browse 20 of your pages on Cassini, and you've used that time anyway ;)

One thing I've noticed isn't always in the guides, is that if you want to debug on a different address than http://localhost/ you need to manually set the host to your local IIS. This is done by adding a line in the hosts file, located at

C:\Windows\system32\drivers\etc\hosts

Open the file with notepad (you need to "Run as Administrator" in order to be able to save if you're using Windows Vista and have User Account Control turned on...) and add your host. For example, to debug under http://mysite/ you add

mysite         127.0.0.1
Tomas Aschan
  • 53,075
  • 51
  • 214
  • 362
  • I'm going to try this right now. Much better to simulate production while debugging, right? – Portman Apr 27 '09 at 22:21
  • Hmm... if I'm understanding this correctly, it requires you to "Publish" all of your changes. That seems like a show-stopper. If I change something in my view or stylesheet, I want to be able to save and refresh, without adding an extra step in there. Would you mind elaborating on how you have this setup on your dev box? – Portman Apr 27 '09 at 22:29
  • PS: If you want me to open a new question "How do I debug ASP.NET applications under IIS7 on Vista" I will do that so that you can get the +15 rep bump. – Portman Apr 27 '09 at 22:32
  • Reputation isn't all that matters. It's just motivation for us to help - which I apparently already did, right? But I did take a look around and couldn't find that question on SO yet, so maybe it needs to be asked... ;) – Tomas Aschan Apr 27 '09 at 22:45
  • Here you are, kind sir: http://stackoverflow.com/questions/795642/how-do-you-debug-asp-net-applications-under-iis7-on-vista – Portman Apr 27 '09 at 23:10
  • Just a small point, but this method makes branching in TFS painful, because you'll end up with multiple websites pointing at the same IIS virtual directory and TFS throws a wobbly. – Rebecca May 18 '11 at 08:04
  • I never debug using cassini, only ever with IIS on my dev machine. You can still debug like you would in Cassini, you just have to use the Attach To Process option in the debug menus (Ctrl-Alt-P) and find the correct w3wp.exe for the required site.. better simulates what your prod/staging servers will be like anyway. As for needing multiple host file entries, what does it matter if you have 10-20 extra lines in there; just add a new one for each site and set the correct bindings in IIS. site.localhost, site2.localhost, site3.localhost, etc. – Ads May 29 '15 at 12:22