J
JMUApache
Hi:
I have got a problem with FromsAuthentication for many days.
I use "Forms" Authentication in my ASP.NET Web Froms, and I find
that I can't singout....
Some Code Here:
//In my Logon.aspx, I got the username and password
//then I check these in my database
//logon.aspx
protected void btnLogin_Click(object sender, EventArgs e)
{
long sid = Student.TestPassword(username, password);
if (sid == -1) return false;
Student student = new Student(sid);
SchoolPrincipal principal = new SchoolPrincipal(student);
String userdata = principal.Identity.ToString();
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1, username, DateTime.Now,
DateTime.Now.AddMinutes(20), false, userdata);
string encyptionTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new
HttpCookie(FormsAuthentication.FormsCookieName, encyptionTicket);
authCookie.Expires = DateTime.Now.AddMinutes(5);
Response.Cookies.Add(authCookie);
return true;
}
//SchoolPrincipal is a class interface IPrincipal
//I create it on my logon.aspx
//and rebuild it in my gobal.asax
//gobal.asax
protected void Application_AuthenticateRequest(object sender,
System.EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (null == authCookie) return;
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch
{
return;
}
SchoolPrincipal principal = new
SchoolPrincipal(authTicket.UserData);
if (principal.Identity == null) return;
else Context.User = principal;
}
//that is part of my code
//Login is OK, but it Will never logout until I close the navigater
//My Logout Code Here
private void Logout ()
{
FormsAuthentication.SignOut();
}
So, I have trap for many days
Any help would be appriciate
Thanks
//Chen
I have got a problem with FromsAuthentication for many days.
I use "Forms" Authentication in my ASP.NET Web Froms, and I find
that I can't singout....
Some Code Here:
//In my Logon.aspx, I got the username and password
//then I check these in my database
//logon.aspx
protected void btnLogin_Click(object sender, EventArgs e)
{
long sid = Student.TestPassword(username, password);
if (sid == -1) return false;
Student student = new Student(sid);
SchoolPrincipal principal = new SchoolPrincipal(student);
String userdata = principal.Identity.ToString();
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1, username, DateTime.Now,
DateTime.Now.AddMinutes(20), false, userdata);
string encyptionTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new
HttpCookie(FormsAuthentication.FormsCookieName, encyptionTicket);
authCookie.Expires = DateTime.Now.AddMinutes(5);
Response.Cookies.Add(authCookie);
return true;
}
//SchoolPrincipal is a class interface IPrincipal
//I create it on my logon.aspx
//and rebuild it in my gobal.asax
//gobal.asax
protected void Application_AuthenticateRequest(object sender,
System.EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (null == authCookie) return;
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch
{
return;
}
SchoolPrincipal principal = new
SchoolPrincipal(authTicket.UserData);
if (principal.Identity == null) return;
else Context.User = principal;
}
//that is part of my code
//Login is OK, but it Will never logout until I close the navigater
//My Logout Code Here
private void Logout ()
{
FormsAuthentication.SignOut();
}
So, I have trap for many days
Any help would be appriciate
Thanks
//Chen