Logout Problem in .net 2.0
-
Hi Friends, I have a simple web applicaiton in .net 2.0 i am writing in c#. Now i am facing the problem in Logout is that, Once i click Logout it takes me back to my Login Page. But in case if i use Back Button from Browser it goes inside the last page i was. I clear all the cookies and all required things to be done on Logout. But about this Back Button. I dont know. I have searched alot for this but i really didnt find any proper solution to it. Any help regarding this will be appreciated. Thanks
Cheers Menon
-
Hi Friends, I have a simple web applicaiton in .net 2.0 i am writing in c#. Now i am facing the problem in Logout is that, Once i click Logout it takes me back to my Login Page. But in case if i use Back Button from Browser it goes inside the last page i was. I clear all the cookies and all required things to be done on Logout. But about this Back Button. I dont know. I have searched alot for this but i really didnt find any proper solution to it. Any help regarding this will be appreciated. Thanks
Cheers Menon
If you use the Session object you can call Session.Abandon() which will clear it then just put checks in the Page_Load of each page that checks if the Session is null and if so redirects them to the login page.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Hi Friends, I have a simple web applicaiton in .net 2.0 i am writing in c#. Now i am facing the problem in Logout is that, Once i click Logout it takes me back to my Login Page. But in case if i use Back Button from Browser it goes inside the last page i was. I clear all the cookies and all required things to be done on Logout. But about this Back Button. I dont know. I have searched alot for this but i really didnt find any proper solution to it. Any help regarding this will be appreciated. Thanks
Cheers Menon
M_Menon wrote:
Now i am facing the problem in Logout is that, Once i click Logout it takes me back to my Login Page.
This is because your page is cached in the user's machine. When you hit back it normally loads from the temporary internet files where normally the files will download. To overcome this problem you need to set cacheability to your pages. Try any of this code which remove the cacheability of your web page,
Response.Cache.SetCacheability(HttpCacheability.Server);
or
Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
or
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Venkatesh Mookkan My: Website | Yahoo Group | Blog Spot
-
If you use the Session object you can call Session.Abandon() which will clear it then just put checks in the Page_Load of each page that checks if the Session is null and if so redirects them to the login page.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
Hi there, When you Click the Back Button, it doesnt call the Page_Load method. So even if your Session is Abandon, the page will be visible. Yes But after that he wont be able to do any other function since it will go to the Page_Load Method. But the Page is still visible which is what i dont want. Thanks,
Cheers Menon
-
M_Menon wrote:
Now i am facing the problem in Logout is that, Once i click Logout it takes me back to my Login Page.
This is because your page is cached in the user's machine. When you hit back it normally loads from the temporary internet files where normally the files will download. To overcome this problem you need to set cacheability to your pages. Try any of this code which remove the cacheability of your web page,
Response.Cache.SetCacheability(HttpCacheability.Server);
or
Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
or
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Venkatesh Mookkan My: Website | Yahoo Group | Blog Spot
Hi Venkatesh, Thanks for the reply, I have tired almost everything to stop by using cookie and all other things possible. But nothing worked. I added your code but still nothing worked. I am putting my Logout Click Method Code here ******************************** HttpCookie aCookie; string cookieName; int limit = Request.Cookies.Count; for (int i = 0; i < limit; i++) { cookieName = Request.Cookies[i].Name; aCookie = new HttpCookie(cookieName); aCookie.Expires = DateTime.Now.AddDays(-30); Response.Cookies.Add(aCookie); } Response.Buffer = true; Response.Expires = 0; Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); Response.CacheControl = "no-cache"; Response.Cache.SetCacheability(HttpCacheability.Server); FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage("../Login.aspx"); Please have a look and let me know if there is anything i should add anything else :) Thanks
Cheers Menon
-
Hi Venkatesh, Thanks for the reply, I have tired almost everything to stop by using cookie and all other things possible. But nothing worked. I added your code but still nothing worked. I am putting my Logout Click Method Code here ******************************** HttpCookie aCookie; string cookieName; int limit = Request.Cookies.Count; for (int i = 0; i < limit; i++) { cookieName = Request.Cookies[i].Name; aCookie = new HttpCookie(cookieName); aCookie.Expires = DateTime.Now.AddDays(-30); Response.Cookies.Add(aCookie); } Response.Buffer = true; Response.Expires = 0; Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); Response.CacheControl = "no-cache"; Response.Cache.SetCacheability(HttpCacheability.Server); FormsAuthentication.SignOut(); FormsAuthentication.RedirectToLoginPage("../Login.aspx"); Please have a look and let me know if there is anything i should add anything else :) Thanks
Cheers Menon
You have to add my code on the Page Load event.
Venkatesh Mookkan My: Website | Yahoo Group | Blog Spot