• 杂记之web篇


    问题1:通过POST方式提交给后台的数据出现了乱码,用部分浏览器测试却是好的。

    解决办法:

        在web.config文件中加上 <globalization responseEncoding="gb2312" requestEncoding="gb2312" fileEncoding="gb2312"/>。

    如果有中文必须是GB2312。如果是纯数字和字母的输出可以使用UTF-8。

       <system.web>
          <globalization responseEncoding="gb2312" requestEncoding="gb2312" fileEncoding="gb2312"/>
          <httpRuntime requestValidationMode="2.0" />
            <compilation debug="true" targetFramework="4.0" />
        </system.web>


    问题2:提交带有跨站攻击特性的字符串时,比如< ; 等,会报错的问题。

    解决办法:

        在web.config中加上 <pages validateRequest="false"></pages>     

        <system.web>
          <globalization responseEncoding="gb2312" requestEncoding="gb2312" fileEncoding="gb2312"/>
          <httpRuntime requestValidationMode="2.0" />
          <pages validateRequest="false"></pages>      
            <compilation debug="true" targetFramework="4.0" />
        </system.web>
    

    问题3:需要将数据库中的表数据转换为XML时。

    解决办法:

        将表对象转化为泛型数组,然后用linq语法直接遍历每条数据,将每条数据转化为xml格式。

             OrdersManager kom = new OrdersManager();
                kom.DbHelper.ConnectionString =  ConfigurationManager.AppSettings["UserDbConnection"].ToString();
                List<OrdersEntity> OrdersEntityArray = kom.GetDataTableByWhere(conditionstring).ToList<OrdersEntity>();
                var OrdersToXML = new XElement("Orders",
                   from Order in OrdersEntityArray
                   select new XElement("Order",
                       new XElement("OrderNo", Order.OrderNo.ToString()),
                       new XElement("PayType", Order.PayType.ToString()),
                       new XElement("IsNeedInvoice", Order.IsNeedInvoice.ToString()),            
                       new XElement("CreateDate", Order.CreateDate.ToString())
                       ));
                Result = "<?xml version="1.0" encoding="utf-8" ?>
    " + OrdersToXML.ToString();           
                Response.Write(Result);
            }
    
  • 相关阅读:
    【转】关于GRIB数据的处理
    [转载]国际gis遥感杂志
    【转】linux后台运行和关闭、查看后台任务
    OpenXML: excel 插入BarChart图表
    利用.Net Framework2.0 zip压缩、解压 string 数据
    C# 常见面试题(2)
    'String or binary data would be truncated' error message
    Openxml: 导出excel 设置 cell的格式
    OpenXML: Asp.net利用OpenXML 导出Excel.
    C#中文和UNICODE字符转换方法
  • 原文地址:https://www.cnblogs.com/LearningC/p/3687886.html
Copyright © 2020-2023  润新知