正如标题所说,我得到:
Base-64 char数组的长度无效.
我已经在这里阅读了这个问题,似乎建议将ViewState存储在SQL中,如果它很大的话.我正在使用一个带有大量数据收集的向导,所以我的ViewState很可能很大.但是,在我转向"存储在数据库"解决方案之前,也许有人可以看看并告诉我是否有其他选择?
我使用以下方法构建了用于传递的电子邮件:
public void SendEmailAddressVerificationEmail(string userName, string to)
{
string msg = "Please click on the link below or paste it into a browser to verify your email account.<BR><BR>" +
"<a href=\"" + _configuration.RootURL + "Accounts/VerifyEmail.aspx?a=" +
userName.Encrypt("verify") + "\">" +
_configuration.RootURL + "Accounts/VerifyEmail.aspx?a=" +
userName.Encrypt("verify") + "</a>";
SendEmail(to, "", "", "Account created! Email verification required.", msg);
}
Run Code Online (Sandbox Code Playgroud)
Encrypt方法如下所示:
public static string Encrypt(string clearText, string Password)
{
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password, new …Run Code Online (Sandbox Code Playgroud) 在某些情况下,我通过(解密)获得以下异常,我无法确切地知道原因:
Base-64 char数组的长度无效
我的代码:
public static string encodeSTROnUrl(string thisEncode)
{
if (null == thisEncode)
return string.Empty;
return HttpUtility.UrlEncode(Encrypt(thisEncode));
}
// string thisDecode = "3Dn%2bsJJPXprU4%3d"; //this is the value which cause the exception.
public static string decodeSTROnUrl(string thisDecode)
{
return Decrypt(HttpUtility.UrlDecode(thisDecode));
}
QueryStringEncryption.Cryptography.decodeSTROnUrl(Request.QueryString["val"].ToString());
Run Code Online (Sandbox Code Playgroud)
抛出异常的确切行是:
Byte[] byteArray = Convert.FromBase64String(text);
Run Code Online (Sandbox Code Playgroud)
我认为我通过加密和解密操作之前和之后的编码和解码来解决这个问题.但是一些值仍然会引发此异常.
注意:我注意到一些奇怪的行为:作为发送到我的邮件的查询字符串的id是:n%2bsJJPXprU4%3d并且它没有例外地工作..
以及发送网址包含问题的用户 3Dn%2bsJJPXprU4%3d
这是一个浏览器问题?? !!