In my error logs I see the following error and stacktrace:
Page error: URL: /SiteCollectionImages/Push/zh-cn/Machining_calculators.jpg
Debugging enabled: False
Correlation ID: 857a397e-8063-447c-af92-b114074282b8
Message:
Server cannot append header after HTTP headers have been sent.
Source: System.Web
StackTrace: at System.Web.HttpResponse.AppendHeader(String name, String value)
at Microsoft.SharePoint.Publishing.BlobCache.SetResponseHeaders(HttpContext context, BlobCacheEntry target)
at Microsoft.SharePoint.Publishing.BlobCache.SendCachedFile(HttpContext context, BlobCacheEntry target,
SPUserToken currentUserToken, SiteEntry currentSiteEntry)
at Microsoft.SharePoint.Publishing.BlobCache.SendCachedFile(HttpContext context, BlobCacheEntry target, SiteEntry currentSiteEntry)
at Microsoft.SharePoint.Publishing.BlobCache.HandleCachedFile(HttpContext context, BlobCacheEntry target, Boolean anonymousUser, SiteEntry currentSiteEntry)
at Microsoft.SharePoint.Publishing.BlobCache.RewriteUrl(Object sender, EventArgs e, Boolean preAuthenticate)
at Microsoft.SharePoint.Publishing.PublishingHttpModule.AuthorizeRequestHandler(Object sender, EventArgs ea)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
It seems that the inbuilt BlobCache attempts to set httpresponse-headers after response has been sent to server. Does anyone know how to correct this, or is it a bug in the SharePoint-platform?
Update: My web.config looks like this:
<BlobCache location="d:\BlobCache\companyname" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv)$" maxSize="10" enabled="true" />
And it is also worth mentioning that this doesn't happen for all image-requests. Approximately 90-95% of all image request end up being propertly cached in the specified location and sent to the client with proper response codes.
Update2: Hooks into HttpApplication from HttpModules:
app.PreSendRequestContent += new EventHandler(app_PreSendRequestContent);
and some SharePoint specific code in HttpModule:
var spApp = context as SPHttpApplication;
if (spApp != null)
{
var labelHandler = new VaryByLabelHandler();
spApp.RegisterGetVaryByCustomStringHandler(labelHandler);
var countryHandler = new VaryByCountryHandler();
spApp.RegisterGetVaryByCustomStringHandler(countryHandler);
var claimHandler = new VaryByClaimHandler();
spApp.RegisterGetVaryByCustomStringHandler(claimHandler);
}