asp.net 裡 include UTF8 垃圾問題

來源:互聯網
上載者:User
暫且不討論為什麼要用 SSI,而不用其它技術(如 UserControl)

  產生 index.shtml 肯定要帶 BOM,其實帶不帶也不會影響頁面上會出現空白行。

  index.shtml 內容如下:

         < html>
  < body>

  < !--#include file="head.shtml"-->

  < /body>

  < /html>
 
  1、head.shtml 儲存為 UTF-8 帶 BOM 時,會出現空白行(頁面元素當然不止這些)。

  2、head.shtml 儲存為 UTF-8 不帶 BOM 時,會出現亂碼,因為 SSInc.dll 載入這個檔案時,不知道檔案的編碼(因為沒有 BOM 簽名),因此會按 GBK 來負載檔案,最後亂碼。。。

  所以,正也不行,反也不行,只有最後一招了,也是迫不得已。。

  改 index.shtml 為:

        < html>
  < body>

  < !--< !--#include file="head.shtml"-->

  < /body>

  < /html>
 
   在 head.shtml 的頁開頭加上

  < !--BOM-->

    內容

  意圖 將 < !--#include 前的 < !-- 和 head.shtml 裡的 BOM--> 用HTML注釋掉,在 asp 下應該沒有問題。

  2年前,用 asp.net include 就發現一個問題,就是它的解釋方法和 asp 完全不同,不信可以試試

  < !--< !--#include file="head.shtml"-->執行結果等效於

  < !--#include file="head.shtml"-->

  又試了半個小時,幾近絕望,被 IE 這個小小的問題折磨。一陣亂試後發現

  < !--#< !--#include file="head.shtml"-->

被忽略,暫時這樣吧,期待更好的解決方案。。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.