Base-64 char数组的长度无效

时间:2011-02-16 06:57:27

标签: asp.net

我从我们的某个网页收到此错误:“Base-64字符数组的长度无效”。

这是我异常的堆栈跟踪:

at System.Convert.FromBase64String(String s)     
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)     
at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)     
at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState)     
at System.Web.UI.SessionPageStatePersister.Load()

背后的代码.cs:

protected override PageStatePersister PageStatePersister
{
    get
    {
        return new SessionPageStatePersister(Page);
    }
}

什么会导致此错误?

2 个答案:

答案 0 :(得分:2)

如果Base64字符串中有空格,则抛出此错误。我已经看到这种错误编码的Base64字符串从SagePay传递(以前是Protx)。

因为Request.QueryString []对字符串进行解码并将+(base64字符串中的有效字符)视为空格(这是正确的,因为urlencoding将+视为空格。

我在以下文章中写过:

答案 1 :(得分:0)

我在解密过程中遇到同样的问题,当加密字符串中有空格时有时会发生这个问题,我所做的就是用+

替换空格
cryptedString = cryptedString.Replace(" ", "+");

这也可能是你的问题。

相关问题