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)

相关文章:

  • 2022-12-23
  • 2021-07-02
  • 2022-01-30
  • 2021-08-11
  • 2021-11-29
  • 2022-01-09
  • 2022-02-12
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2022-02-23
相关资源
相似解决方案