In my project, a seller can upgrade his role to viewer.
If he upgrades, I should force a logout for that user so that he will
login as a viewer. Can anyone pls tell me how is this done.
The project is in C# 4.
in the section the user can update, once they have updated the role and clicked the button, use the formsauthentication class to log the user out and return them to login page. Or, just update their session to the new role?
Please remember to Mark As Answer if helpful
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)
If he upgrades, I should force a logout for that user so that he will
login as a viewer.
Where you are providing that upgrade feautre, add the below code to the end of it
FormsAuthentication.SignOut();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
FormsAuthentication.RedirectToLoginPage();
suryaacd
Member
108 Points
286 Posts
How can I force a user to log out
Sep 03, 2012 10:30 AM|LINK
Hi,
In my project, a seller can upgrade his role to viewer.
If he upgrades, I should force a logout for that user so that he will
login as a viewer. Can anyone pls tell me how is this done.
The project is in C# 4.
Thanks,
Surya
christiandev
Star
8607 Points
1841 Posts
Re: How can I force a user to log out
Sep 03, 2012 11:05 AM|LINK
in the section the user can update, once they have updated the role and clicked the button, use the formsauthentication class to log the user out and return them to login page. Or, just update their session to the new role?
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)
gopalanmani
Star
7826 Points
1320 Posts
Re: How can I force a user to log out
Sep 03, 2012 11:08 AM|LINK
Hi,
just call FormsAuthentication.Signout() to destroy the FormsAuthentication cookie,
this is an example ,
FormsAuthentication.Signout()
Roles.DeleteCookie();
Session.Clear();
Response.Resirect(FormsAuthentication.LoginUrl)
Gopalan Mani
My Tech blog
ramiramilu
All-Star
95503 Points
14106 Posts
Re: How can I force a user to log out
Sep 03, 2012 11:08 AM|LINK
use FormsAuthentication.SignOut() - http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx
Thanks,
JumpStart
Ruchira
All-Star
43060 Points
7042 Posts
MVP
Re: How can I force a user to log out
Sep 04, 2012 09:55 AM|LINK
Hello,
Where you are providing that upgrade feautre, add the below code to the end of it
FormsAuthentication.SignOut(); Session.Abandon(); // clear authentication cookie HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, ""); cookie1.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(cookie1); // clear session cookie (not necessary for your current problem but i would recommend you do it anyway) HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", ""); cookie2.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(cookie2); FormsAuthentication.RedirectToLoginPage();
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.