Response.Write PDF page by page to avoid timeout excepction

Sergio Moreira de Menezes 0 Reputation points
2025-04-28T22:18:42.7+00:00

Hello, everybody

I have a page which Response.Content is "application/pdf"

This PDF is returned by a lot of api requests putting files together in an unique Byte Array variable. Sometimes, the return could last too much time and pdf file could have lots of megabytes of size.

Because of company restrictions, sometimes, the page returns a timeout exception, and we don't have any margin to increase timeout.

Every request (or every file) has maximum 3 or 4 pages. So, I thought if I can write a code that writes a response file by file without buffering a page (response.buffer = false), using the same resource available to write text, I could fix the problem. But, after some tests I've realized that response.binary write does not work without buffer, and just one file is returned to page.

Is anyone have an a idea to fix this problem?

Thank's in advance

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,230 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 75,051 Reputation points
    2025-04-29T15:45:55.96+00:00

    there is only one response file per http request. Disabling buffering usually improves memory usage, but only a little in actual time. you probably need to make pdf generation faster. You could also just increase the timeout for the request.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.