Mime Sniffing of IE

Source: Internet
Author: User
Ie starts MIME sniffing from SP2. In the past, the browser used Content-Type to determine the type of content of the resoponse stream, and then called an unused handler for processing. For example, text/html indicates that the HTML code is accepted, HTML page rendering is required. Text/JPEG indicates the image files that are accepted. You need to call the processing program for processing JPEG streams through the received data streams.
On this basis, ie adds the MIME sniffing function, not only based on content-type, but also based on the content of the response stream. The value of Content-Type is text/plain. In non-ie browsers, text/plain indicates normal text, and the browser only needs to display the content. However, in IE, if the content of response is similar to the following:
  1. <HTML>
  2. <SCRIPT>
  3. Alert (/XSS /);
  4. </SCRIPT>
  5. </Html>

After executing the MIME sniffing, ie determines that the content is of the text/html type, and then executes the HTML Rendering logic. The/XSS dialog box is displayed in the browser.
According to this feature of IE, in web programs, the returned response must have the correct Content-Type value to avoid ie being "smart ".

The problem is: If we do need to provide users with a normal file for download, the content of this file contains HTML characters in the above format, in this case, the value of Content-Type needs to be set to text/plain (because this file is indeed plain). What should I do?
Solution: Use content-disposition.
Content-Disposition format:
"Content-disposition", "attachment; filename = fname. Ext"
Write the file name (such as foo.txt) after filename.txt. In this case, the browser will pop up a dialog box prompting you whether to save the file.

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.