ASP.NET 4.0,webform网站
我的网站中有一个链接是调用另一个页面并传递url参数,它看起来如下。
http://www.foo.com/foo.aspx?anotherURI?param1=aaa&26param2=bbb
但是,我需要对“anotherURI?param1 = aaa& 26param2 = bbb”进行url编码,因此它变为:
http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb
现在,如果我想用javascript包含它,它将无法正常工作。如何再次对网址进行编码?
javascript:void(window.open('http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb', 'popup'))
答案 0 :(得分:4)
更正URI:
错误:http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb
右:http://www.foo.com/foo.aspx?anotherURI=param1%3Daaa%26param2%3Dbbb
多个URI的示例:http://www.foo.com/foo.aspc?uri1 = [encodedURI]& uri2 = [encodedURI2]
从asp.net上的queryString变量获取值:
Dim sUrl1 as String = request("VarName")
Dim sUrl2 as String = request("VarName")
Dim sUrl3 as String = request("VarName")
如果您想从该变量中获取已解码的URL:
Dim sDecodedUrl1 as String = Server.UrlDecode(sUrl1)
Dim sDecodedUrl2 as String = Server.UrlDecode(sUrl2)
Dim sDecodedUrl3 as String = Server.UrlDecode(sUrl3)
答案 1 :(得分:1)
如果你想编码/解码它(php的方式)使用
function url_encode(str) {
str = (str + '').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
function url_decode(str) {
return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}