Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Base64-encoded parameter in query string

I'm sending a link in my web application to users mails (for confirming user registration) as the following :

<a target="_blank" href="http://localhost:2817/ConfirmRegistration?confirm=Y0tcmGepe7wjH7A1CT1IaA==">
http://localhost:2817/ConfirmRegistration?confirm=Y0tcmGepe7wjH7A1CT1IaA==
</a>

But Chrome alert this message :

Chrome Message

Is the query string invalid ? How can I resolve it ?

BTW:
My application is in C# and MVC3

like image 716
Mohammad Dayyan Avatar asked Jun 26 '12 11:06

Mohammad Dayyan


1 Answers

I was using HttpUtility.UrlEncode but I had problems if the base64 encoded string contained a "+" sign. It was correctly being encoded to "%2b" but when it was coming back from the browser it was interpreted as a space. So, I used two simple encode/decode methods instead:

public static string UrlEncodeBase64(string base64Input)
{
    return base64Input.Replace('+', '.').Replace('/', '_').Replace('=', '-');
}

public static string UrlDecodeBase64(string encodedBase64Input)
{
    return encodedBase64Input.Replace('.', '+').Replace('_', '/').Replace('-', '=');
}
like image 133
Lee Gunn Avatar answered Nov 15 '22 09:11

Lee Gunn