开发者

Why do my ETag headers work under IIS but not under the VS2010 web server?

开发者 https://www.devze.com 2023-03-23 15:30 出处:网络
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());

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 despit开发者_运维知识库e calling Response.Cache.SetCacheability(HttpCacheability.Public), VS/Cassini always returns resources with HTTP Cache-Control set to "private"... does that help?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消