Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click the logout button I want to clear all of the session and not to go to another page without logging in again. I already use a link button and the code is:

'example inside folder sale

Session.Clear()
Response.Redirect("Default.aspx")


The default.aspx page is outside the folder Sale.
The resulting error is:

Request URL :/mywebsite/sale/Default.aspx

I want, after log out from the other page, all to go to Default.aspx page.
I hope somebody can help me..... ;P
Posted
Updated 16-Feb-11 22:01pm
v2

When user logs out clear the session and redirect to sale/Default.aspx.
Response.Redirect("/sale/Default.aspx")
In the page load event of the page check for the session not null. If the session is empty then redirect the user to /sale/Default.aspx page.
 
Share this answer
 
A simple bit of code to clear the session + forms authentication would be..

C#
Session.Abandon();
FormsAuthentication.SignOut();



Then, have a look at this tip from Sandeep.

Browser back button issue after logout[^]

You need to disable the 'back' button behaviour available for cached pages
 
Share this answer
 
You need to log the user out, and clear the authorization cookie.
Try:
C#
FormsAuthentication.SignOut();
Session.Abandon();

// Clear the authentication cookie
HttpCookie c = new HttpCookie(FormsAuthentication.FormsCookieName, "");
c.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(c);

// Clear session cookie - shouldn't be needed, but hey-ho.
c = new HttpCookie("ASP.NET_SessionId", "");
c.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(c);

FormsAuthentication.RedirectToLoginPage();


or, in VB:
VB
FormsAuthentication.SignOut()
Session.Abandon()
' Clear the authentication cookie
Dim c As New HttpCookie(FormsAuthentication.FormsCookieName, "")
c.Expires = DateTime.Now.AddYears(-1)
Response.Cookies.Add(c)
' Clear session cookie - shouldn't be needed, but hey-ho.
c = New HttpCookie("ASP.NET_SessionId", "")
c.Expires = DateTime.Now.AddYears(-1)
Response.Cookies.Add(c)
FormsAuthentication.RedirectToLoginPage()
 
Share this answer
 
Hi,
jai7486

you can use
FormsAuthentication.Signout();

Thanks,
Prasant
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900