CSDN是中国软件开发联盟的意思么?
这是我的登录页面记住密码的实现方法,用到了FormsAuthenticationTicket。
protected void AddCooike(string uname, string upwd)
{
string userInfo = uname + '|' + FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPwd.Text.Trim(), "MD5").ToString();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "coo", DateTime.Now, DateTime.Now.AddDays(10), false, userInfo);
string cookieStr = FormsAuthentication.Encrypt(ticket);
HttpCookie userCookie = new HttpCookie("coo");
userCookie.Value = cookieStr;
userCookie.Expires = DateTime.Now.AddDays(5);
HttpContext.Current.Response.Cookies.Add(userCookie);
}
然后,用户再次登录的时候
string mess = Request.Cookies["coo"].Value;
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(mess);
string[] strInfo = ticket.UserData.Split('|');
string userName = strInfo[0].ToString();
string userPwd = strInfo[1].ToString();
在VS2008中调试的时候,偶尔出现(偶尔就是有时再现,有时不出现)下面的问题:
填充无效,无法被移除。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Security.Cryptography.CryptographicException: 填充无效,无法被移除。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[CryptographicException: 填充无效,无法被移除。]
System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) +1473532
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +306
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +30
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo) +159
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +247
search.Page_Load(Object sender, EventArgs e) +418
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
然后,当将项目布置到本地IIS中的时候,这个问题就始终出现了。
VS2008提示是 FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(mess);这里的问题。
可是应该怎么修改代码呢。项目很快就要上交了,望软件开发者联盟里面的各路高手搭打手啊!