js 编码、解码与asp.net 编码、解码
2016-04-07 20:22
766 查看
js对URL提供:escape,encodeURI,encodeURIComponent 的编码方法encodeURIComponent:推荐使用,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,以是假定给背景转达参数必要利用encodeURIComponent时必要背景解码对utf-8撑持(form中的编码体例和当前页面编码体例不异)
1、escape:不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
2、encodeURI:不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
3、encodeURIComponent:不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
JS编码:var result=encodeURIComponent(unit);
asp.net解码:Server.UrlDecode(Request["result"]);
js函数:
encodeURI("url")//编码
decodeURI("url")//解码
asp.net的函数:
Server.UrlEncode("url")//编码
Server.UrlDecode("url")//解码
JS对URL中的特殊字符的URL编码,函数是encodeURIComponent,这个函数编码等于asp.net中的Server.UrlEncode体例。
在asp.net中,利用Request.QueryString[""].ToString()可以直接对编码后的字符串进行解码,也可利用Server.UrlDecode体例进行解码。
在asp.net中,可利用Request.Url.OriginalString来得到URL,利用Request.Url.ToString(),得到到的地点则是解码过的。
下面是一些使用例子:
View Code
1、escape:不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
2、encodeURI:不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
3、encodeURIComponent:不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
JS编码:var result=encodeURIComponent(unit);
asp.net解码:Server.UrlDecode(Request["result"]);
js函数:
encodeURI("url")//编码
decodeURI("url")//解码
asp.net的函数:
Server.UrlEncode("url")//编码
Server.UrlDecode("url")//解码
JS对URL中的特殊字符的URL编码,函数是encodeURIComponent,这个函数编码等于asp.net中的Server.UrlEncode体例。
在asp.net中,利用Request.QueryString[""].ToString()可以直接对编码后的字符串进行解码,也可利用Server.UrlDecode体例进行解码。
在asp.net中,可利用Request.Url.OriginalString来得到URL,利用Request.Url.ToString(),得到到的地点则是解码过的。
下面是一些使用例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://localhost:3281/Js/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript"> var url = "http://www.cnblogs.com/linJie1930906722?test=测试js对URL的编码"; var escape_Url = escape(url); //escape_Url=http%3A//www.cnblogs.com/linJie1930906722%3Ftest%3D%u6D4B%u8BD5js%u5BF9URL%u7684%u7F16%u7801 var decodeURI_Url = decodeURI(url); // decodeURI_Url=http://www.cnblogs.com/linJie1930906722?test=测试js对URL的编码 var decodeURIComponent_Url = decodeURIComponent(url); //decodeURIComponent_Url=http://www.cnblogs.com/linJie1930906722?test=测试js对URL的编码 var result = "escape_Url=" + escape_Url + " decodeURI_Url=" + decodeURI_Url + " decodeURIComponent_Url=" + decodeURIComponent_Url; console.log(result); alert(result); </script> </head> <body> </body> </html>
View Code
相关文章推荐
- asp.net TextBox文本框背景透明+浅色背景文字提示
- C# ASP.NET MVC 图片盗链 加水印 的问题
- 如何在asp.net程序集中添加winform的选择框(确定,取消)
- ASP .NET 如何在 SQL 查询层面实现分页
- ASP .NET 如何在 SQL 查询层面实现分页
- ASP.NET中TextBox设置只读时不能取值的处理
- ASP.NET常用的SqlDbHelper类
- 基于AspectJ自定义注解
- ASP.NET-页面传值
- asp.net的简易的参数化查询
- 理解ASP.NET MVC的DependencyResolver组件
- ASP.Net MVC Action重定向跳出Controller和Area
- 对casper源码的一次改动
- 项目:信息交流平台系统
- 树莓派Raspberry Pi首次安装配置
- 处理JasperServer返回List类型到Ireport的参数
- ASP.NET MVC 学习笔记(1)
- 图文详解远程部署ASP.NET MVC 5项目
- ASP.NET Core中的依赖注入(3): 服务的注册与提供
- ASP.NET MVC路由配置详解