UTF8 file garbled problem and resolution when IIS deploys log site

Source: Internet
Author: User
The cause of the problem

To facilitate viewing of the online problem log, a new site is created on IIS on the server, the root directory points to the log directory, and directory browsing begins;
Well, you can enter the site, see the list of directories, find a TXT file, click to see the Log, Yi, how the Chinese into the #%$@

Well, this problem has always been dealt with by clicking on the Chrome menu = "More tools =" code = "UTF8 can be solved,
I skillfully open the menu, I find, find, Find, the Code menu where to go ... What the heck.
Originally, Chrome said its automatic detection function is very cow B, the coding options to remove, removed ...

What to do. Can only start from the IIS server, search for half a day of data, find a solution, in the site root directory web.config add the following configuration:

<?xml version= "1.0" encoding= "UTF-8"?>
<configuration>
  <system.webServer>
    < httpprotocol>
      <customHeaders>
        <add name= "Content-type" value= "text/plain; Charset=utf-8"/>
      </customHeaders>
    

Well, sure enough, TXT file is not garbled.
Wait, how does the directory list become HTML ...
The above configuration in the plain, change into text/html how to do.
I go, TXT file again into HTML to parse, so there will be XSS attack possible ah ...
Changed to be as follows, without any effect:

<add name= "Content-type" value= "Charset=utf-8"/>

Finally, he groped for a long time, found the solution, or change web.config, the content is as follows, simply to set the txt extension mimetype:

<?xml version= "1.0" encoding= "UTF-8"?>
<configuration>
    <system.webServer>
        < Directorybrowse enabled= "true" showflags= "Date, Time, Size, Extension, longdate"/>
        <staticContent>
            <remove fileextension= ". txt"/>
            <mimemap fileextension= ". txt" mimetype= "text/plain;charset=utf-8"/ >
        </staticContent>
    </system.webServer>
</configuration>

Finally, self-review: Can I not be so smart ...

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.