Problem With Froms Authentication. HELP

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
 
P

Patrick.O.Ige

When you say it will never logout are u expecting the below to fire??:-
private void Logout ()
{
FormsAuthentication.SignOut();
}
Where is the page you are redirecting it to for it to logout(it needs to go
somewhere)
Rote






JMUApache said:
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
 
J

JMUApache

Hi

It redirect to default page logon.aspx
but it doesn't signout

I have try use code like this
Session.Abandon ();
Response.Cookie.Clear ();
//somebody has suggest me do this


but it does nothing

So what is wrong with my web application?

Any suggest would be appriciate.
Thanks

//chen



When you say it will never logout are u expecting the below to fire??:-
private void Logout ()
{
FormsAuthentication.SignOut();
}
Where is the page you are redirecting it to for it to logout(it needs to go
somewhere)
Rote






JMUApache said:
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
 
P

Patrick.O.Ige

Chen do you want it to do what the code below says?:-
Session.Abandon ();
Response.Cookie.Clear ();
Beacuse i don't understand if you say it doesn't do anything?
Or may be what you want to achieve is after logging out and
try going back you want the user to log in again.
Which means you want to clear the session ,cookies etc?
Patrick

JMUApache said:
Hi

It redirect to default page logon.aspx
but it doesn't signout

I have try use code like this
Session.Abandon ();
Response.Cookie.Clear ();
//somebody has suggest me do this


but it does nothing

So what is wrong with my web application?

Any suggest would be appriciate.
Thanks

//chen



When you say it will never logout are u expecting the below to fire??:-
private void Logout ()
{
FormsAuthentication.SignOut();
}
Where is the page you are redirecting it to for it to logout(it needs to go
somewhere)
Rote






JMUApache said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top