How to pass plus sign in input parameter?

How do I pass an email address with a plus sign in my input parameter?

Username Value " johnsmith+1@gmail.com "

http://domain.com/ page1.aspx?username=johnsmith+1@gmail.com

? Doesn't this seem to work?

+3
source share
7 answers

Use the Server.UrlEncode method if you can:

Codebehind:

string email = "johnsmith+1@gmail.com"
lnkThingy.NavigateUrl = "http://www.website.com/Page1.aspx?email=" + Server.UrlEncode(email);
+2
source

You can use the HttpUtility.UrlEncode method.

http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

+4
source

URL- . "domain.com", , .

URL- :

 http://domain.com/page1.aspx?username=johnsmith%2b1@gmail.com

'+' == ascii 43 == 0x2B. Url - " , "

+1

JohnSmith% 2b1% 40gmail.com

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS G:\Users\Max> [reflection.assembly]::loadwithpartialname("System.Web")

GAC    Version        Location
---    -------        --------
True   v2.0.50727     G:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll


PS G:\Users\Max> [web.httputility]::UrlEncode("johnsmith+1@gmail.com")
johnsmith%2b1%40gmail.com
PS G:\Users\Max>
+1

HttpUtility.UrlEncode. , - , URL-. :

johnsmith%2b1%40gmail.com

+ @ , %. (www.asciitable.com).

+1

.NET , UrlDecode. .

    /// <summary>
    /// Character Encodes a (string).  Specifically used for Querystring parameters.
    /// </summary>
    /// <remarks></remarks>
    /// <param name="String"></param>
    /// <returns>string</returns>
    public static string EncodeForQueryString(this string String)
    {
        String = System.Web.HttpUtility.UrlEncode(String);
        return String;
    }

    /// <summary>
    /// Character Decodes a (string).  Specifically used for Querystring parameters.
    /// </summary>
    /// <remarks>The plus sign causes issues when using System.Web.HttpUtility.UrlDeEncode.  The plus sign is often decoded before it reaches this method.  This method will replace any extra + with %2b before attempting to decode</remarks>
    /// <param name="String"></param>
    /// <returns>string</returns>
    public static string DecodeForQueryString(this string String)
    {
        String = String.Replace("+", "%2b");
        String = System.Web.HttpUtility.UrlDecode(String);
        return String;
    }

querystring:

string myUrl = "myPage.htm?q=" + "Saving+Silverman".ToString().EncodeForQueryString();

querystring:

string myDecodedString = Request.Params["q"].DecodeForQueryString();
+1

(+) . . , a + .

, convert + symbol % 2B, . .

protected void btnRedirect_Click(object sender, EventArgs e)
{
    string signature="f1wRcMvJJ2YjLjc8dc+7ykY9szg=&kanna";
    signature = signature.Replace("+", "%2B");
    Response.Redirect("Encode-Decode-QueryString.aspx?sign=" +     Server.UrlEncode(signature));
}

. .

http://www.dotnetpickles.com/2014/02/aspnet-how-to-pass-plus-in-query-string.html

thank

0
source

Source: https://habr.com/ru/post/1762876/


All Articles