Click here to Skip to main content
15,884,648 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi.

I'm developing a web application, where one of the requirement is to automaticly logout user after 15 mins interval. I set this in my web.config
<forms loginUrl="Login.aspx" timeout="15"/>   


where user will be automatically logout (to login page) after 15 minutes.

I have a listing to show which users is online.But this users will be shown when user is logged in and will remain as online for 15 minutes eventhough user click logout button (using login status).It seems like the when i click logout, the seesion time is still ongoing.

I want to clear the session time when i click the logout button. Means now session will timeout after 15 minutes,but when i click the logout button,i want the session to be ended before that 15 minutes.

I tried using these codes to end the timeout ;

C#
Session.Clear();
Session.Abandon();
Session.RemoveAll();
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
Roles.DeleteCookie();


but nothing is seems to be working.The timeout will only end after the 15 minutes.
I used in the event of LoginStatus1_LoggedOut and/or LoginStatus1_LoggingOut, but i cant figure out why its not working.

Can anyone help me on this?Any ideas/suggestion guys?
Posted

Looks like i have to clear the cache as well ;

C#
string sKey = (string)Session["user"];
        string sUser = Convert.ToString(Cache[sKey]);
        Cache.Remove(sUser);
 
Share this answer
 
Hi ,

Mention Your All Stuff in Global.asax file in following method as mentioned

C#
public void Session_End(object s, EventArgs e)
{
     Session.Clear(); 
        Session.Abandon();
        Session.RemoveAll();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
        Roles.DeleteCookie();
}
 
Share this answer
 
Comments
pwtc222 22-Nov-11 2:08am    
still the same, no difference
Hi,
C#
Put it under Page_Load

public void Page_Load(object sender, EventArgs e)
{

Session.Clear();
Session.Abandon();
Session.RemoveAll();
FormsAuthentication.SignOut();
FormsAuthentication.RedirectToLoginPage();
Roles.DeleteCookie();



}
 
Share this answer
 
create logout.aspx page and copy the code....

C#
protected void Page_Load(object sender, EventArgs e)
   {
       Session.Abandon();
       Response.Redirect("../Login.aspx");
   }
 
Share this answer
 
put this code in page_load

if (Session["Uid"] == null)
{
Response.Redirect("Login.aspx");
}

hope it is useful for you
from vikranth reddy
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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