Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:12:22+00:00 2026-05-26T06:12:22+00:00

I have an ASP.Net site that streams back a PDF document after a postback

  • 0

I have an ASP.Net site that streams back a PDF document after a postback to the initial page. In IE, Chrome, Firefox, and on iPhones and iPads, everything works fine, the PDF is sent to the browser. On Android phones, I get an error stating that the PDF is invalid. The code below is a simplified version of what I am trying to do, but it does reproduce the error. I basically have a button on a web page that is set to run at server. On the first request of the page it displays the HTML and after the button click, it should render the PDF:

protected void Page_Load(object sender, EventArgs e)
{

    Response.ClearHeaders();
    Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
    Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
    Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
    Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
    Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 
    Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 
    Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 
    Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 
    Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 
    Response.AppendHeader("Expires", "0"); // HTTP 1.1 

    if (IsPostBack)
    {
        Response.ClearContent();
        Response.ClearHeaders();

        string fullPath = @"C:\Temp\outdoc.pdf";

        if (System.IO.File.Exists(fullPath))
        {

            //Set the appropriate ContentType.
            Response.ContentType = "application/pdf";
            //Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment;filename=\"TestDoc.pdf\"");

            byte[] b = System.IO.File.ReadAllBytes(fullPath);
            this.Page.Response.AddHeader("Content-Length", b.Length.ToString());

            //Write the file directly to the HTTP content output stream.
            Response.BinaryWrite(b);
            Response.Flush();
            Response.End();
            Response.Close();

        }
    }


}

I have played a lot with different values in the headers and different ways of closing and flushing the response stream with no luck. Has anyone seen this before or can anyone offer any suggestions on things to try.

Edit: I have found out that this only happens when I do a postback to the page. If I just stream the document right off the bat, the document streams correctly. This leads me to believe it is some sort of caching problem with the android browser.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:12:22+00:00Added an answer on May 26, 2026 at 6:12 am

    Try transfer current request to other handler where you render PDF directly to response stream.

    Your page code:

    if (IsPostBack)
    {
      Context.Server.Transfer("RenderPDF.ashx");
      Response.End();
    }
    

    And in that new RenderPDF.ashx, move here that code responsible for rendering pdf file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET Site that has a single Master Page. On one of
I have a page on my ASP.NET site that has a Repeater control to
I have a asp.net web site, I would like a page on that site
I have an ASP.NET site that has been running perfectly for a long time,
I have an ASP.NET site that I'm developing. The layout is pretty basic. The
I have a asp.net web site that was developed on the .Net Framework v2
I have a asp.net mvc site that references a couple of libraries. Recently I
We have an ASP.NET application running at a customer site that uses ActiveDirectory for
I have an old ASP.NET 1.1 site that I am maintaining. We are working
I have an ASP.NET 3.5 e-commerce site that has an admin section. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.