A white screen solution appears when a large PDF file is output to the client.

Source: Internet
Author: User
Our website provides PDF resources for users to download. Some of the PDF files are large, and the CPU usage of the IIS process is high during operation for a period of time, and the memory usage increases. The performance of the client is to output a white screen. After IIS is restarted, services can be provided.

     

    Cause:

    When ASP. net auxiliary process (aspnet_wp.exe, for applications running on Internet Information Service 6.0 [IIS], w3wp.exe) sends data to Microsoft Internet Information Service (inetinfo.exe or dllhost.exe) when executing a File Download request.

     

    According to the computer configuration, the IIS process may process data or cache the data in the memory. If the file is too large, data will be cached in the memory when the two processes communicate with each other. This may increase the memory usage on the server. The cause of this error is the memory limit on the Web server.

     

    Solution:

    Solution 1:

    Large files are cut into small data blocks and then gradually added to the output stream. Sample Code provided on msdn

  1. Code
    System. Io. Stream istream = NULL;

    // Buffer to read 10 K bytes in Chunk:
    Byte [] buffer = new byte [10000];

    // Length of the file:
    Int length;

    // Total Bytes to read:
    Long datatoread;

    // Identify the file to download including its path.
    String filepath = "downloadfilename ";

    // Identify the file name.
    String filename = system. Io. Path. getfilename (filepath );

    Try
    {
    // Open the file.
    Istream = new system. Io. filestream (filepath, system. Io. filemode. Open,
    System. Io. fileaccess. Read, system. Io. fileshare. Read );


    // Total Bytes to read:
    Datatoread = istream. length;

    Response. contenttype = "application/octet-stream ";
    Response. addheader ("content-disposition", "attachment; filename =" + filename );

    // Read the bytes.
    While (datatoread> 0)
    {
    // Verify that the client is connected.
    If (response. isclientconnected)
    {
    // Read the data in buffer.
    Length = istream. Read (buffer, 0, 10000 );

    // Write the data to the current output stream.
    Response. outputstream. Write (buffer, 0, length );

    // Flush the data to the HTML output.
    Response. Flush ();

    Buffer = new byte [10000];
    Datatoread = datatoread-length;
    }
    Else
    {
    // Prevent infinite loop if user disconnects
    Datatoread =-1;
    }
    }
    }
    Catch (exception ex)
    {
    // Trap the error, if any.
    Response. Write ("error:" + ex. Message );
    }
    Finally
    {
    If (istream! = NULL)
    {
    // Close the file.
    Istream. Close ();
    }
    }

  2. Solution 2:
  3. Modify the <compilation DEBUG = "true" batch = "false"> Configuration section in the web. config file of the website to <compilation DEBUG = "false" batch = "false">

    Description on msdn:

    When you are in ASP. NET Application Web. when the debug attribute value of the compilation element is set to false in the config file. set the scripttimeout attribute to an appropriate value. By default, the server. scripttimeout value is set to 90 seconds. However, when the debug attribute is set to true, the server. scripttimeout value is set to a very large value (30,000,000 seconds ). As a developer, you must be aware of the potential impact on the behavior of your asp. NET web application.

     

    Because the development environment will default the web when we create a web application. this configuration section of config is changed to a debug state, which reduces the performance of Web applications. Therefore, this configuration is often ignored during deployment. Check your configuration file. For more information about the Asp.net configuration file, see:

    Http://msdn.microsoft.com/zh-cn/architecture/kza1yk3a.aspx

     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.