Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: When You Call the Response.ClearHeaders Method in a Custom HTTPmodule, Extra Characters Are Appended to the Output


View products that this article applies to.

Symptoms

When you call the Response.ClearHeaders method in a custom HTTPModule that is registered with PreSendRequestHeaders, extra characters are returned. This problem occurs only on the first request or the first time that you make this call after you compile the application.

↑ Back to the top


Cause

For the first request of a page, the compiler tries to do a batch compile and takes a different code path in the Response.Flush method. Later in the code, when you try to add chunkprefix and chunksuffix characters, they appear as extra characters in the output.

↑ Back to the top


Resolution

How to Obtain the Hotfix

This issue is fixed in the June 2003 ASP.NET Hotfix Package 1.1. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
821156 INFO: ASP.NET 1.1 June 2003 Hotfix Rollup Package
You cannot obtain this fix individually. You must install the rollup.

Note When you request this hotfix, you receive the rollup.

The English version of this hotfix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
	           Date         Time   Version       Size       File name
		   -----------------------------------------------------------------------
		   07-Jun-2003  00:44  1.1.4322.910    253,952  Aspnet_isapi.dll
		   07-Jun-2003  00:44  1.1.4322.910     20,480  Aspnet_regiis.exe
		   07-Jun-2003  00:44  1.1.4322.910     32,768  Aspnet_wp.exe
		   15-May-2003  23:49                   33,522  Installpersistsqlstate.sql
		   15-May-2003  23:49                   34,150  Installsqlstate.sql
		   07-Jun-2003  12:52  1.1.4322.910  1,216,512  System.dll
		   07-Jun-2003  00:39                   14,472  Webuivalidation.js
		   07-Jun-2003  12:52  1.1.4322.910  1,249,280  System.Web.dll

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Save the following code as Stripheader.cs, and then compile this application to Test.dll:
    using System.Web ;
    using System;
    using System.IO;
    
    namespace failed
    {
    	/// <summary>
    	/// Summary description for the stripheader.
    	/// </summary>
    	public class stripheader: IHttpModule 
    	{
    		private MyEventHandler _eventHandler = null;
    
    		public stripheader()
    		{
    			//
    			// TODO: Add constructor logic here.
    			//
    		}
    		public void Init (HttpApplication app)
    		{
    			app.PreSendRequestHeaders  += new EventHandler (onPreSend);
    		}
    
    		public void Dispose(){}
    		public delegate void MyEventHandler(Object s, EventArgs e);
    		public event MyEventHandler MyEvent
    		{
    			add { _eventHandler += value; }
    			remove { _eventHandler -= value; }
    		}
    
    		public void onPreSend(Object s, EventArgs e)
    		{
    			HttpApplication app = s as HttpApplication;
    			app.Context.Response.ClearHeaders();
    
    			if(_eventHandler!=null)
    				_eventHandler(this, null);
    		}
    	}
    	
    }
  2. Use the following code to create a Test.aspx page:
    <%@ Page %>
    <%
    Response.Write ("Hello World");
    %>
  3. Add a default Web.config file, and then add the following section just before the end </system.web> tag:
      <httpModules>
             <add name="failed" type="failed.stripheader, test" />
      </httpModules>
  4. Copy the files that you created in steps 1, 2, and 3 to a virtual directory (vdir). Create a bin folder in this virtual directory, and then copy the Test.dll file to the bin folder.
  5. View the Test.aspx page in your browser.

    The expected text output is "Hello World". However, the result is "b Hello World 0 ".
After the page has been compiled one time, it returns the correct output for all later requests. To reproduce the behavior again, modify the Web.config file, re-save the file, and then view the Test.aspx page again.

↑ Back to the top


Keywords: kbqfe, kbhttpmodule, kbnetframe100presp3fix, kbfix, kbqfe, kbbug, kbhotfixserver, KB812686

↑ Back to the top

Article Info
Article ID : 812686
Revision : 7
Created on : 9/27/2005
Published on : 9/27/2005
Exists online : False
Views : 392