简体   繁体   English

发送带有多个查询字符串的 url 作为 asp.net 中的查询字符串参数

[英]send a url with multiple querystring as a querystring parameter in asp.net

I need to send a redirect url as a query string parameter, unfortunately this url contains more than one querystring parameter as follows我需要发送一个重定向 url 作为查询字符串参数,不幸的是,这个 url 包含多个查询字符串参数,如下所示

"http://host:port/page2.aspx?param1=value&param2=value&param3=value" “http://host:port/page2.aspx?param1=value&param2=value&param3=value”

the problem is when I encode this url and send it via querystring , it looks as if it wasn't encoded , so my application consider the redirect url parameter value to be only问题是当我编码这个 url 并通过 querystring 发送它时,它看起来好像没有编码,所以我的应用程序认为重定向 url 参数值是唯一的

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

and consider并考虑

"&param2=value&param3=value" "&param2=value&param3=value"

as a part of the current url作为当前网址的一部分

I tried Server.UrlEncode and Server.HtmlEncode我试过Server.UrlEncodeServer.HtmlEncode

string myUrl = “http://host:port/page2.aspx?param1=value&param2=value&param3=value”;

string EncodedUrl = myUrl.EncodeTo64();

Pass this as querystring and retrieve using :将此作为查询字符串传递并使用以下方法检索:

    EncodedUrl.DecodeFrom64();

Functions:职能:

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;

    }

Replace '&' in your url with '%26' or use Server.UrlEncode将 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM