Search

Response.Flush clears Content-Type header by Richard Deeming

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 480689
Opened: 8/4/2009 7:40:42 AM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
In IIS7 integrated pipeline mode, a call to Response.Flush causes the response to be sent without the content-type header unless a content-length has also been specified. In IIS6 or classic pipeline mode, the content-type header is sent as expected.
Details (expand)
Product Language
English

Version

.NET Framework 3.5 SP1
Operating System
Windows Vista
Operating System Language
English
Steps to Reproduce
1. Create a generic handler which sets the content type but not the content length, calls Response.Flush, and then writes the content;

2. Request the handler from an IIS6 site, or IIS7 in classic pipeline mode - observe that the content-type header is sent;

3. Request the handler from an IIS7 site in integrated pipeline mode - the content-type header is not sent;


Example:
context.Response.ContentType = "text/x-vCard";
context.Response.AddHeader("Content-Disposition", "filename=\"Test.vcf\";");
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetExpires(context.TimeStamp + TimeSpan.FromHours(-1));
context.Response.Cache.SetNoServerCaching();
context.Response.Cache.SetNoStore();
context.Response.Flush();
context.Response.Write(...);
Actual Results
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Transfer-Encoding: chunked
Expires: -1
Server: Microsoft-IIS/7.0
Content-Disposition: filename="Test.vcf";
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 04 Aug 2009 14:37:16 GMT
Expected Results
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/x-vCard
Expires: -1
Server: Microsoft-IIS/7.0
Content-Disposition: filename="Test.vcf";
X-Powered-By: ASP.NET
Date: Tue, 04 Aug 2009 14:38:10 GMT
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
File Name Submitted By Submitted On File Size  
TestContentType.zip (restricted) 8/4/2009 -
Sign in to post a comment.
Posted by Microsoft on 9/23/2009 at 10:16 AM
This issue will be fixed in the next major release of the ASP.NET and the .NET Framework.

Thank you for submitting this issue on Connect.
Posted by Microsoft on 8/6/2009 at 8:13 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you
Posted by Microsoft on 8/5/2009 at 2:55 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com/)
Posted by Richard Deeming on 8/4/2009 at 7:44 AM
The issue appears to be in the internal HttpResponse.UpdateNativeResponse method:

if (((this._contentType != null) && this._contentTypeSet) && ((bufferedLength > 0L) || this._contentLengthSet))
{
    HttpHeaderCollection headers = this.Headers as HttpHeaderCollection;
    string str = this.AppendCharSetToContentType(this._contentType);
    headers.Set("Content-Type", str);
    this._contentTypeSet = false;
}

If the content length has not been set and no content has been generated, the content type header will not be sent.

In contrast, for IIS6 or classic pipeline mode, the WriteHeaders method calls GenerateResponseHeaders, which has:

if ((this._statusCode != 0xcc) && (this._contentType != null))
{
    string str2 = this.AppendCharSetToContentType(this._contentType);
    headers.Add(new HttpResponseHeader(12, str2));
}
Sign in to post a workaround.