|
MSDN上面的例子有点小问题.他存储用户登录信息是用加密Cookies来做的.需要以下地方修改代码:
private void Button1_Click(object sender, System.EventArgs e) { bool isAuthenticated = IsAuthenticated( txtUserName.Text,txtPassword.Text ); if (isAuthenticated == true ) { string roles = GetRoles( txtUserName.Text, txtPassword.Text ); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version txtUserName.Text, // user name DateTime.Now, // creation DateTime.Now.AddMinutes(60),// Expiration false, // Persistent roles ); // User data
string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted ticket to the // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);//MSDN上面没有写这一句,加上就可以了!
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserName.Text, false )); } }
我已经将修改好的例子上传,你可以参照一下!
|