以下是登陆页面中的代码:
if ((new UserSystem()).GetUserByUserName(Tx_Account.Text, password))
{
int RightNumber=(new UserSystem()).GetUserRightNumber(Tx_Account.Text);
FormsAuthenticationTicket ticket=new FormsAuthenticationTicket(
1, Tx_Account.Text, DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
RightNumber.ToString()); string CookieStr=FormsAuthentication.Encrypt(ticket);
HttpCookie cookie=new HttpCookie(FormsAuthentication.FormsCookieName,CookieStr);
cookie.Path=FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(cookie);
FormsAuthentication.RedirectFromLoginPage("*", false);
}
else
{
MismatchLabel.Visible = true;
} 登陆成功以后,我的程序在另一个页面的Page_Load()中读出cookie中的FormsAuthenticationTicket读出FormsAuthenticationTicket的测试代码如下:
string hhh=Context.Request.Cookies[FormsAuthentication.FormsCookieName].Value;
FormsAuthenticationTicket Ticket = FormsAuthentication.Decrypt(Context.Request.Cookies[FormsAuthentication.FormsCookieName].Value);string username=Ticket.Name;
string haha=Ticket.UserData;我跟踪执行了整个过程,如果我用admin登陆, 写入的cookie的ticket的name=admin, UserData=5
但是我读出cookie之后还原成FormsAuthenticationTicket 发现Ticket的name=* UserData=null(空)真不知道这是怎么回事!不够分, 等几天有分了加分! 谢谢!!
if ((new UserSystem()).GetUserByUserName(Tx_Account.Text, password))
{
int RightNumber=(new UserSystem()).GetUserRightNumber(Tx_Account.Text);
FormsAuthenticationTicket ticket=new FormsAuthenticationTicket(
1, Tx_Account.Text, DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
RightNumber.ToString()); string CookieStr=FormsAuthentication.Encrypt(ticket);
HttpCookie cookie=new HttpCookie(FormsAuthentication.FormsCookieName,CookieStr);
cookie.Path=FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(cookie);
FormsAuthentication.RedirectFromLoginPage("*", false);
}
else
{
MismatchLabel.Visible = true;
} 登陆成功以后,我的程序在另一个页面的Page_Load()中读出cookie中的FormsAuthenticationTicket读出FormsAuthenticationTicket的测试代码如下:
string hhh=Context.Request.Cookies[FormsAuthentication.FormsCookieName].Value;
FormsAuthenticationTicket Ticket = FormsAuthentication.Decrypt(Context.Request.Cookies[FormsAuthentication.FormsCookieName].Value);string username=Ticket.Name;
string haha=Ticket.UserData;我跟踪执行了整个过程,如果我用admin登陆, 写入的cookie的ticket的name=admin, UserData=5
但是我读出cookie之后还原成FormsAuthenticationTicket 发现Ticket的name=* UserData=null(空)真不知道这是怎么回事!不够分, 等几天有分了加分! 谢谢!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货