0

In my ASP.NET MVC 2 app, I have the following lines:

Response.Cache.SetMaxAge(TimeSpan.FromDays(90));
Response.Cache.SetETag(lastWriteTime.Value.Ticks.ToString());

Using Fiddler to trace the HTTP streams, I can see:

ETag: 634473035667000000

in the Response Headers when running under IIS7, but when I'm running under the Visual Studio 2010 web server, this header just... disappears. Whether I set it via Response.Cache.SetETag() or via Response.AppendHeader("ETag", etag), it just never gets returned.

Is this a "feature" of the IIS web server? Is there some config setting I've missed? It's going to make testing cache invalidation a bit fiddly if I have to attach to the IIS process to be able to debug anything...

EDIT: It also appears that despite calling Response.Cache.SetCacheability(HttpCacheability.Public), VS/Cassini always returns resources with HTTP Cache-Control set to "private"... does that help?

Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
  • 1
    one after the other: `alt, d, p, enter, w, enter.` attach your ass to w3wp faster than you can say "debug"! – Andrew Bullock Jul 26 '11 at 19:44
  • @Andrew... (1) I know, (2) it's Alt-D,P,W,Down,Down,Enter because there's normally more than one w3wp running on this box, and (3) there's a whole bunch of NServiceBus hosts and stuff running alongside it that makes debugging outside the VS debugger a little more involved than that... but mainly I'm just hacked off that it SHOULD work and it doesn't :) – Dylan Beattie Jul 26 '11 at 19:46
  • Cassini has issues with some MIMETypes and headers. Have you tried using IIS Express or full on IIS? – JamesEggers Jul 26 '11 at 19:47
  • ah the dreaded multiple w3wp scenario. which one is it?! – Andrew Bullock Jul 26 '11 at 20:03

2 Answers2

5

The ETag will be suppressed if you use HttpCacheability.Private.

You can find more information on Why does HttpCacheability.Private suppress ETags?

If you change it to HttpCacheability.ServerAndPrivate it should work

Community
  • 1
  • 1
Pedro
  • 2,300
  • 1
  • 18
  • 22
  • I already had HttpCacheability set to HttpCacheability.Public, but Cassini was ignoring that as well - but you're absolutely right, setting it to ServerAndPrivate has done the trick. Thank you! – Dylan Beattie Jul 26 '11 at 19:58
4

Simple - it's Cassini.

Cassini isn't meant to be a production server, but is there to facilitate debugging (which is why it overrides caching too - after all if you recompile and rerun would you want your new code not touched because a page is cached?)

If you want your debugging to work as it would in IIS then IISExpress is where you should be going... there's no attach problem there as it will spin up a real instance of IIS, but in your own user context.

blowdart
  • 55,577
  • 12
  • 114
  • 149