当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net 里 include UTF8 垃圾问题

ASP.NET
Asp.Net 通用数据操作类 (附通用数据基类)
asp.net汉字转拼音和获取汉字首字母的代码
asp.net 多字段模糊查询代码
OpenCms 带分页的新闻列表
URLRewriter最简单入门介绍 URLRewriter相关资源
asp.net Repeater取得CheckBox选中的某行某个值
asp.net清空Cookie的两种方法
asp.net一些很酷很实用的.Net技巧
asp.net生成高质量缩略图通用函数(c#代码),支持多种生成方式
asp.net TripleDES加密、解密算法
Asp.net中防止用户多次登录的方法
asp.net Repeater取得CheckBox选中的某行某个值的c#写法
asp.net DataGridView导出到Excel的三个方法[亲测]
C#,winform,ShowDialog,子窗体向父窗体传值
asp.net学习中发现的比较完整的流程
ASP.net 页面被关闭后,服务器端是否仍然执行中?
asp.net Context.Handler 页面间传值方法
asp.net xml序列化与反序列化
asp.net实例代码protected override void Render(HtmlTextWriter writer)
asp.net(c#)捕捉搜索引擎蜘蛛和机器人

ASP.NET 中的 asp.net 里 include UTF8 垃圾问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 171 ::
收藏到网摘: n/a

    暂且不讨论为什么要用 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"-->

被忽略,暂时这样吧,期待更好的解决方案。。