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.

Downloading a .pdf file fails when Internet Information Services (IIS) is configured to use System.Web.StaticFileHandler for static files.


View products that this article applies to.

Symptoms

Consider  the following scenario.  You have an ASP.NET 2.0 or ASP.NET 3.5 website running on Microsoft Internet Information Services (IIS).  The website has the .pdf file extension mapped to the ASP.NET 2.0 ISAPI Aspnet_isapi.dll file. Additionally, you have configured the  System.Web.StaticFileHandler http Handler to handle the .pdf extension.

You attempt to browse to a .pdf file on the website using Microsoft Internet Explorer, and you have the Adobe Reader plug-in installed in the browser.  While downloading the .pdf file, Internet Explorer hangs and the download does not complete.  At the same time, the following exception error message is logged in the Application event log of the IIS server: 

 

Event Type:         Warning
Event Source:     ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID:              1309
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
 
Exception information:
    Exception type: ArgumentException
    Exception message: Object must be an array of primitives.
Parameter name: src
 
Request information:
    Request URL:
http://localhost/test.pdf
    Request path: /test.pdf
    User host address: 127.0.0.1
    User: 
    Is authenticated: False
    Authentication Type: 
    Thread account name: NT AUTHORITY\NETWORK SERVICE
 
Thread information:
    Thread ID: 1
    Thread account name: NT AUTHORITY\NETWORK SERVICE
    Is impersonating: False
    Stack trace:    at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
   at System.Web.StaticFileHandler.ProcessRangeRequest(HttpContext context, String physicalPath, Int64 fileLength, String rangeHeader, String etag, DateTime lastModified)
   at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)
   at System.Web.StaticFileHandler.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 

↑ Back to the top


Cause

This issue occurs due to a problem with the StaticFileHandler while processing Ranged requests that have a buffer size greater than 16. The default range buffer size is 16. The Adobe PDF web browser plug-in uses Ranged HTTP requests and may send more than 16 ranged fragments for large .pdf files.  In this scenario, the StaticFileHandler attempts to resize its buffer by calling the Buffer.BlockCopy function, which results in the web browser hanging and the download failing.

 

↑ Back to the top


Resolution

To avoid this problem, use one of the following options: 

 

  1. Use  the default httpHandler System.Web.DefaultHttpHandler for .pdf files instead of System.Web.StaticFileHandler.
  2. Disable the �Display PDF in browser� Adobe Reader feature in Internet Explorer, and instead let Internet Explorer handle the download natively.  In this scenario, the .pdf file can be opened using Adobe Reader once the download is completed.
  3. Disallow ranged requests by placing the following code into global.asax:

 

<script language="c#" runat="server">
 protected void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
      HttpApplication app = (HttpApplication) sender;
      if (string.Equals(app.Context.CurrentHandler.GetType().FullName,
                    "System.Web.StaticFileHandler",
                    StringComparison.OrdinalIgnoreCase))
      {
            app.Response.AppendHeader("Accept-Ranges", "none");
      }
 }
</script>

 

 

↑ Back to the top


More information

Microsoft has confirmed this is a problem in ASP.NET version 2.0.

 

↑ Back to the top


Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

↑ Back to the top


Keywords: KB2026272

↑ Back to the top

Article Info
Article ID : 2026272
Revision : 7
Created on : 6/8/2010
Published on : 6/8/2010
Exists online : False
Views : 602