* A garbled solution occurs when users download files containing Chinese characters.

Source: Internet
Author: User

 

ASPProgramThe response. Redirect "URL of the file to be downloaded" method is used to download the file. However, when the file name contains Chinese characters and users click Download and save, the file name is garbled in the Save As dialog box.

Solution:

1, when the browser "always send URL via UTF-8" removed

In this way, the URL will be sent through the default encoding of the operating system. The URL is treated as the default encoding of the operating system. In our IIS Chinese version, the default string encoding is gb2312 (GBK ). The client and the server are both encoded using gb2312 (GBK), so there will be no garbled characters.

This method is not suitable. Because we need to coordinate the client and server

2. When we know that IE processes the file name, it is handled as UTF-8 encoding by default, and our URL is sent in gb2312 encoding, so garbled characters may occur. Therefore, we only need to convert gb2312 encoding to UTF-8 encoding on the server side.

As follows:CodeAs shown in:

Defaultcodepage = session. codePage
Session. codePage = 65001 'utf-8
Pfilename = server. urlencode (pfilename) 'encode file name by UTF-8
Session. codePage = defacodecodepage 'Restore

<Script language = "JavaScript">
Window. navigate ("<% = pfilename %> ")
</SCRIPT>

Note that the above Code does not use: Response. Redirect pfilename

This is because the Redirect method will encode the string, which will encode % in pfilename as % 2e.

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.