2

我需要发送一个重定向 url 作为查询字符串参数,不幸的是这个 url 包含多个查询字符串参数,如下所示

“http://host:port/page2.aspx?param1=value¶m2=value¶m3=value”

问题是当我编码这个 url 并通过 querystring 发送它时,它看起来好像没有编码,所以我的应用程序认为重定向 url 参数值只是

“http://host:port/page2.aspx?param1=value”

并考虑

"¶m2=值¶m3=值"

作为当前网址的一部分

我试过Server.UrlEncodeServer.HtmlEncode

4

3 回答 3

2
string myUrl = “http://host:port/page2.aspx?param1=value&param2=value&param3=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;

    }
于 2012-12-02T15:43:44.183 回答
0

将 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'");
于 2012-12-02T16:18:14.837 回答
0

对 URL 进行编码

System.Web.HttpUtility.UrlEncode(string url)
于 2012-12-02T16:19:57.817 回答