• SSI下shtml页面include问题


    关于shtml页面include问题解决方案

     
    这几天再做站点静态化工作,本以为很简单的事情,不想实际实现过程中还是遇到了些小问题
     
    页面上有一些是公用嵌套页如head.inc,bottom.inc等,为了修改维护方便决定使用shtml的include来解决,随之问题来了
     
    <!--#include file=”head.inc”-->这样包含后发现页面上会出现一个空行,网上查资料后发现是因为utf-8的BOM头引起的,于是测试结果如下
    head.inc编码为utf-8有bom时
    *.aspx页面<!--#include file=”head.inc”-->没有任何问题
    *.shtml页面<!--#include file=”head.inc”-->在引用的地方会出现一个空行
    head.inc编码为utf-8无bom时
    *.aspx页面<!--#include file=”head.inc”-->页面出现乱码
    *.shtml页面<!--#include file=”head.inc”-->没有任何问题
    google了一番,找到如下解决方案,希望对遇到此问题的朋友有所帮助
    解决方案1.
    1.修改head.inc编码格式为utf-8无bom
    2.配置文件中添加以下节点
      <system.web>
       <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8"/>
      </system.web>
      这里最主要的是fileEncoding="utf-8"可以解决.aspx文件include的乱码问题
      下面是用c#创建无bom的utf8编码文件方法(默认创建的文件都是utf-8+bom的)
    System.Text.UTF8Encoding utf8=new System.Text.UTF8Encoding(false);
                using (StreamWriter sr = new StreamWriter(filePaht, false, utf8))
                {
                    sr.Write(fileContet)
                }
     这样以后indclude的空行和乱码问题就都解决了
     
    解决方案2.
    head.inc文件编码为utf-8+bom(这样可以避免.aspx文件include的乱码问题)
    在需要include地方这样写
    <!--#<!--#include file="head.inc"-->
    在需要include的文件中如head.inc头部加上一段注释如:<!--bom-->
    这样以后可以实现同样效果
    ps:这种方式时需要添加注释的地方必须在head.inc顶部,不可以这样写<!--#<!--#include file="head.inc"--><!--bom-->
     
     
    分类: Asp.Net
  • 相关阅读:
    深入了解ibatis源码----简单ibatis示例代码
    struts深入理解之登录示例的源码跟踪
    struts深入原理之RequestProcessor与xml
    struts学习
    Debugging WebLogic Server Applications Using Eclipse and the WebLogic-Plugin
    论做人与做事
    网络编程I/O功能介绍
    Python标准库:内置函数format(value[, format_spec])
    swift 笔记 (七) —— 关闭
    在自由软件的价值
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3082267.html
Copyright © 2020-2023  润新知