About shtml line feed ASPX page include garbled Problem Solution

Source: Internet
Author: User
I thought it was a very simple task to do static chemical work on the site over the past few days. I don't want to encounter some small problems in the actual implementation process. Some of the pages are public nested pages such as head. INC, bottom. INC and so on. To facilitate modification and maintenance, we decided to use the shtml include to solve the problem. <! -- # Include file = "head. INC "--> after this is included, an empty line will appear on the page. After checking the information on the Internet, it is found that it is caused by the UTF-8 BOM header. Therefore, the test result is as follows: Head. when Inc is encoded as UTF-8 and BOM is available *. ASPX page <! -- # Include file = "head. Inc" --> no problem *. shtml page <! -- # Include file = "head. Inc" --> A blank line of head. Inc is encoded as UTF-8 without Bom *. ASPX page appears in the referenced area. <! -- # Include file = "head. Inc" --> the page contains garbled characters *. shtml <! -- # Include file = "head. Inc" --> there is no problem. Google has found the following solution and hopes to help the users who encounter this problem. Solution 1. 1. Modify the head. inc encoding format to UTF-8 without adding the following node to the bom2. configuration file <system. Web> <globalization requestencoding = "UTF-8" responseencoding = "UTF-8" Fileencoding = "UTF-8" /> </System. web> the most important thing here is fileencoding = "UTF-8. the following describes how to use C # To create a UTF-8 encoded file without BOM (the files created by default are UTF-8 + BOM) System. Text. utf8encoding utf8 = new system. Text. utf8encoding (false ); Using (streamwriter sr = new streamwriter (filepaht, false, utf8 )) { Sr. Write (filecontet) } In this way, the empty lines and garbled characters of indclude will be solved. Solution 2. The head. inc file is encoded as UTF-8 + BOM (this can avoid garbled characters in the. aspx File Include). <! -- # <! -- # Include file = "head. Inc" --> Add a comment to the head. inc header in the file to be included, for example: <! -- Bom --> in this way, the same effect can be achieved. PS: In this method, the comment must be added at the top of head. Inc. It cannot be written like this. <! -- # <! -- # Include file = "head. Inc" --> <! -- Bom --> it helped a lot. Thanks for your originality.

Note:ArticleOwnerLazy fat rabbitOriginal: the copyright is shared by the author and the blog. You are welcome to reprint it. However, you must keep this statement without the author's consent and give it clearly on the article page.Link: http://www.cnblogs.com/lzrabbit/archive/2011/09/21/2184532.html

If you think this article is good, clickRecommendationWith your support, you can stimulate the author's enthusiasm for writing. Thank you very much.

If you have any questions, you can contact me via lzrabbit@126.com.

I thought it was a very simple task to do static chemical work on the site over the past few days. I don't want to encounter some small problems in the actual implementation process. Some of the pages are public nested pages such as head. INC, bottom. INC and so on. To facilitate modification and maintenance, we decided to use the shtml include to solve the problem. <! -- # Include file = "head. INC "--> after this is included, an empty line will appear on the page. After checking the information on the Internet, it is found that it is caused by the UTF-8 BOM header. Therefore, the test result is as follows: Head. when Inc is encoded as UTF-8 and BOM is available *. ASPX page <! -- # Include file = "head. Inc" --> no problem *. shtml page <! -- # Include file = "head. Inc" --> A blank line of head. Inc is encoded as UTF-8 without Bom *. ASPX page appears in the referenced area. <! -- # Include file = "head. Inc" --> the page contains garbled characters *. shtml <! -- # Include file = "head. Inc" --> there is no problem. Google has found the following solution and hopes to help the users who encounter this problem. Solution 1. 1. Modify the head. inc encoding format to UTF-8 without adding the following node to the bom2. configuration file <system. Web> <globalization requestencoding = "UTF-8" responseencoding = "UTF-8" Fileencoding = "UTF-8" /> </System. web> the most important thing here is fileencoding = "UTF-8. the following describes how to use C # To create a UTF-8 encoded file without BOM (the files created by default are UTF-8 + BOM) System. Text. utf8encoding utf8 = new system. Text. utf8encoding (false ); Using (streamwriter sr = new streamwriter (filepaht, false, utf8 )) { Sr. Write (filecontet) } In this way, the empty lines and garbled characters of indclude will be solved. Solution 2. The head. inc file is encoded as UTF-8 + BOM (this can avoid garbled characters in the. aspx File Include). <! -- # <! -- # Include file = "head. Inc" --> Add a comment to the head. inc header in the file to be included, for example: <! -- Bom --> in this way, the same effect can be achieved. PS: In this method, the comment must be added at the top of head. Inc. It cannot be written like this. <! -- # <! -- # Include file = "head. Inc" --> <! -- Bom --> it helped a lot. Thanks for your originality.

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.