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

ASP.NET
深入理解__doPostBack 客户端调用服务端事件
asp.net(c#)利用构造器链的代码
asp.net Repeater绑定时使用函数
asp.net下linkbutton的前后台使用方法
ASP.NET编程中经常用到的27个函数集
asp.net高效替换大容量字符实现代码
asp.net(c#) ubb处理类
ASP.NET中的跳转 200, 301, 302转向实现代码
C#中的委托和事件学习(续)
asp.net网站安全从小做起与防范小结
asp.net 网页编码自动识别代码
asp.net HttpWebRequest自动识别网页编码
asp.net中调用winrar实现压缩解压缩的代码
dz asp.net论坛中函数--根据Url获得源文件内容
.NET 扩展实现代码
用Jquery访问WebService并返回Json的代码
asp.net(c#)判断远程图片是否存在
asp.net保存远程图片的代码
Asp.Net类库中发送电子邮件的代码
ASP.NET表单验证方法详解

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 172 ::
收藏到网摘: 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"-->

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