正如标题所说,我得到了:
Base-64字符的长度无效 array.
我在这里读到过这个问题,看起来 如果视图状态很大,建议将其存储在SQL中.我是 使用具有大量数据收集的向导,因此有可能 我的视图状态是否很大.但是,在我转向"Store-in-DB"之前 解决方案,也许有人能看一看,告诉我有没有 还有其他 Select 吗?
我使用以下方法构建要交付的邮箱:
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);
}
加密方法如下所示:
public static string Encrypt(string clearText, string Password)
{
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
以下是Hotmail中的HTML外观:
请点击下面的链接或
http://localhost:1563/Accounts/VerifyEmail.aspx?a=YOHY57xYRENEOu3H+FGq1Rf09AZAI56EPjfwuK8XWKg=
在接收端,验证邮箱.aspx.cs page有这样一句话:
string username = Cryptography.Decrypt(_webContext.UserNameToVerify, "verify");
以下是UserNameToVerify的getter:
public string UserNameToVerify
{
get
{
return GetQueryStringValue("a").ToString();
}
}
下面是GetQueryStringValue方法:
private static string GetQueryStringValue(string key)
{
return HttpContext.Current.Request.QueryString.Get(key);
}
解密方法如下所示:
public static string Decrypt(string cipherText, string password)
{
**// THE ERROR IS THROWN HERE!!**
byte[] cipherBytes = Convert.FromBase64String(cipherText);
这个错误可以通过代码修复来修复吗?或者我必须在数据库中存储ViewState吗?