zoukankan      html  css  js  c++  java
  • Server.UrlPathEncode和Server.UrlEncode的区别

    Server.UrlPathEncode默认使用的是utf-8编码而Server.UrlEncode默认为系统默认编码(一般是gb2312)

    Server.UrlDecode默认使用系统编码解码。所以这里容易发生路径解码成乱码的问题。

    Response.Write(Server.UrlDecode(Server.UrlPathEncode("中文")) & "<hr>") Response.Write(HttpUtility.UrlDecode(Server.UrlPathEncode("中文"), Encoding.UTF8) & "<hr>")

    解决办法: 解码的地方使用utf-8编码。HttpUtility.UrlDecode(Server.UrlPathEncode(String),  Encoding.UTF8);

                  或者编码的地方使用Server.UrlEncode(),编解码的默认编码方式都用gb2312;

    URL编码: System.Web.HttpUtility.UrlEncode(string); Server.UrlEncode(string); System.Web.HttpUtility.UrlPathEncode(string); Server.UrlPathEncode(string);

    UrlEncode与UrlPathEncode编码规范不一样 比如: UrlEncode对整个URL进行编码(即http://www.website.com/全部编码) UrlPathEncode对http://之后的内容进行编码(即www.website.com)

  • 相关阅读:
    Vue--路由
    Vue -- 双向过滤器去除html标签
    SQL表的基本操作
    .NET面试题
    MVC Razor
    MVC aspx
    CSS修改滚动条样式
    C# 制作图片验证码
    上传图片加水印
    eclipse常用快捷键
  • 原文地址:https://www.cnblogs.com/lh123/p/3998198.html
Copyright © 2011-2022 走看看