Cannot open PDF on iPad from ASP.NET

I download PDF (and other types, but focus on PDF) through the IIS ASP.NET web application. Downloading works on any platform other than Safari on the iPad and iPhone 4S. I know that iOS does not support downloading documents, but Safari also does not open a PDF file. Clicking on the link does not respond to the device. I tried a couple of solutions listed below (take out / replace headers mostly):

http://nilangshah.wordpress.com/2007/05/28/successfully-stream-a-pdf-to-browser-through-https/ and PHP: Download script file does not work on iPad

I see no errors on the device other than the "expected MIME", but I also see that in desktop browser versions it does not stop loading. I start the proxy server and see that the device receives a 200 response with the appropriate headers. I have successfully opened PDF from other sites using the device.

I'm just starting to remember with ASP and iOS, so any debugging ratings will also be appreciated.

This is what the code looks like:

context.Response.Buffer = false; context.Response.Clear(); context.Response.ClearHeaders(); context.Response.ClearContent(); context.Response.ContentType = "application/pdf"; string fileName = "thefile.pdf"; System.Web.HttpBrowserCapabilities browser = context.Request.Browser; //I have tried with and without all the possbilities in the condition below if (!browser.Browser.Equals("iPad")) { if (isDownload || viewers.Length == 0) context.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", fileName)); else context.Response.AppendHeader("Content-Disposition", "filename=" + fileName); }else { //context.Response.AppendHeader("Content-Disposition", string.Format("inline; filename=\"{0}\"", fileName)); } FileStream iStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); long fileSize = iStream.Length; long fileLengthToRead = fileSize; int chunckSize = 10000; byte[] buffer = new byte[chunckSize]; context.Response.AppendHeader("Content-Length", fileSize.ToString()); context.Response.AppendHeader("X-Content-Type-Options", "nosniff"); try { while (fileLengthToRead > 0 && context.Response.IsClientConnected) { int read = iStream.Read(buffer, 0, chunckSize); context.Response.OutputStream.Write(buffer, 0, read); context.Response.Flush(); fileLengthToRead = fileLengthToRead - read; } } catch (HttpException) { } finally { iStream.Close(); iStream.Dispose(); } break; 

And here is what the headers look like:

 GET http://sample.com/sample.pdf HTTP/1.1 Host: sample.com Accept-Encoding: gzip, deflate Accept-Language: en-us User-Agent: Mozilla/5.0 (iPad; U; CPU OS 4_3_4 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8K2 Safari/6533.18.5 Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Referer: http://sample.com/sample.aspx HTTP/1.1 200 OK Cache-Control: private Content-Length: 218882 Content-Type: application/pdf Server: Microsoft-IIS/7.5 X-Content-Type-Options: nosniff X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 01 Aug 2012 15:41:06 GMT 
+4
source share

All Articles