[英]append a parameter to querystring of existing url asp.net mvc
[英]send a url with multiple querystring as a querystring parameter in asp.net
我需要发送一个重定向 url 作为查询字符串参数,不幸的是,这个 url 包含多个查询字符串参数,如下所示
“http://host:port/page2.aspx?param1=value¶m2=value¶m3=value”
问题是当我编码这个 url 并通过 querystring 发送它时,它看起来好像没有编码,所以我的应用程序认为重定向 url 参数值是唯一的
“http://host:port/page2.aspx?param1=value”
并考虑
"¶m2=value¶m3=value"
作为当前网址的一部分
我试过Server.UrlEncode
和Server.HtmlEncode
string myUrl = “http://host:port/page2.aspx?param1=value¶m2=value¶m3=value”;
string EncodedUrl = myUrl.EncodeTo64();
将此作为查询字符串传递并使用以下方法检索:
EncodedUrl.DecodeFrom64();
职能:
public static string EncodeTo64(this string target)
{
byte[] toEncodeAsBytes
= System.Text.ASCIIEncoding.ASCII.GetBytes(target);
string returnValue
= System.Convert.ToBase64String(toEncodeAsBytes);
return returnValue;
}
public static string DecodeFrom64(this string target)
{
byte[] encodedDataAsBytes
= System.Convert.FromBase64String(target);
string returnValue =
System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
return returnValue;
}
将 url 中的 '&' 替换为 '%26' 或使用 Server.UrlEncode
Responsse.redirect("redirectURL?a='http://url2?a=5%26b=7'&b=9'");
or
Responsse.redirect("redirectURL?a="+Server.UrlEncode("http://url2?a=5&b=7")+"&b=9'");
对网址进行编码
System.Web.HttpUtility.UrlEncode(string url)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.