Setting Cache-Control to Public in WebHandler does not work

  • Thread starter Thread starter Sebastian Paul
  • Start date Start date
S

Sebastian Paul

Hi,

the task is easy: I want to have the Cache-Control set to Public.

void IHttpHandler.ProcessRequest(HttpContext context)
{
const int maxAge = 10;
_context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(maxAge));
_context.Response.Cache.SetMaxAge(new TimeSpan(0, 0, maxAge));
_context.Response.Cache.SetCacheability(HttpCacheability.Public);
_context.Response.Cache.SetLastModified(DateTime.Now);
_context.Response.Cache.SetValidUntilExpires(true);
...
}

Things work fine, output is actually cached by ASP.NET, the HTTP
header value of max-age counts down to zero until content expires.
Only the Cache-Control keeps being private. Why?? I explicitly set the
value to HttpCacheability.Public...

Thanks for any help.
Sebastian
 
Now I noticed that the same applies to ASPX Pages. Fortunately, I had
a look on our production envirionment (IIS) - Cache-Control is
actually Public there!
It turns out that the ASP.NET Development Server (aka Cassini) always
sets to Private (as well as it only allows private connections). That
makes sense and is good, but one has to know it...

Kind regards, Sebastian
 
Back
Top