Issue with Base64-encoded parameter in query string

后端 未结 5 1750
星月不相逢
星月不相逢 2021-01-18 08:56

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



        
5条回答
  •  深忆病人
    2021-01-18 09:11

    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('-', '=');
    }
    

提交回复
热议问题