2012年6月20日 星期三

[Javascript][ASP.NET]Javascript編碼,解碼。ASP.NET(C#)對應之編碼,解碼


escape不編碼字符有69個:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不編碼字符有82個:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不編碼字符有71個:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
1.
JS: escape :
js使用數據時可以使用escape
例如:搜藏中history紀錄。
0-255以外的unicode值進行編碼時輸出%u****格式,其它情况下escape,encodeURI,encodeURIComponent編碼結果相同。
解碼使用:unescape
C#:
HttpUtility.UrlEncode 
HttpUtility.UrlDecode

2.
JS: encodeURI :
進行url跳轉時可以整體使用encodeURI
例如:Location.href=encodeURI("http://cang.baidu.com/do/s?word=百度&ct=21");
解碼使用decodeURI();
C#: decodeURIComponent

3.
JS: encodeURIComponent :
傳遞參數時需要使用encodeURIComponent,這樣組合的url才不會被#等特殊字符截斷。 
例如:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7& u='+encodeURIComponent("http://cang.baidu.com/bruce42")+'">退出</a& gt;');</script>
解碼使用decodeURIComponent()
C#:
[HttpContext.Current.]Server.UrlDecode

[HttpContext.Current.]Server.UrlEncode

沒有留言:

張貼留言