Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,

I have one problem like i want to remove session using session id but problem is it's not remove it's id is stay there so my code is not working

MY CODE:
C#
for (int i = 0; i < Repeater1.Items.Count; i++)
    {
        if    (((HtmlInputCheckBox)Repeater1.Items[i].FindControl("chk")).Checked)
        {
            string tempCompID = ((HtmlInputCheckBox)Repeater1.Items[i].FindControl("chk")).Value;
            Hashtable ht = (Hashtable)Application["SESSION_LIST"];//HERE i have get All session's list
                      ht.Remove(tempCompID);
            Session.Remove(tempCompID);
        }
    }

after that my total session number is dcreased but that session which i have remove it's in client browser working so i want to remove session at admin's side using session id.
please hurry up guys my work is stucked...:(
Posted
Updated 2-Jul-12 3:59am
v5

I have interpretted your question as:-

You are a admin and you wanted to terminate other user's sessions from your admin panel.

There is no inbuilt mechanism to access other user's session values.

In your code when you do
C#
Session.Remove(tempCompID);
its actually removing the session from your session collection not from the other user's

I thought of three options to resolve your issue
1.we can workaround on this by changing the Session Mode to SQLServer
and delete the session id from the corresponding tables
so once you delete the record from the session table then the user wont be able to continune using the same session id

2.Create a table where you can store the user name and the active session id

access this table in admin panel/form

delete the entry/mark the entry as deleted for a specified session id

in the page load you can always check the value from this table for the specific session id if it's not available then do
C#
Session.Abandon();
so the current users session will be ended

3.Create an Application level object to store the Logged In User Id, Application["LoggedUsers"] value needs to be set in Session_Start event in global.asax and remove them in Session_End, store the LoggedIn user as List<sting>. I hope you are already validating session in page load, so add on more line to check the user id is exist in Application["LoggedUsers"] if yes continue else call Session.Abandon(); . Now the main thing is that in your admin form which ever user's session needs to be killed then remove the correpsonding user from the Application["LoggedUsers"].

mark it as solution, if it resolved you issue
 
Share this answer
 
v2
Comments
Pankaj Nikam 2-Jul-12 10:37am    
Good Solution +5 :)
bbirajdar 10-Jul-12 6:46am    
Hey Pankaj..Balaji here
Shemeer NS 2-Jul-12 11:00am    
Thank you :)
Ankur Ramanuj 4-Jul-12 7:30am    
ya you are right but i want to restrict the user my mean is in my application only 4 user is loged in if user's 5 is coming and 4 user allready logging than number 5 is not able to login...than admin forcefully signout any of the four user and 5 is able to login..so how can i forcefully signout the user.
bbirajdar 4-Jul-12 9:26am    
Use any of the three strategies mentioned above..It will suffice your purspose
It's done by this coding..

Hashtable ht = (Hashtable)HttpContext.Current.Application["SESSION_LIST"];
           IDictionaryEnumerator en = ht.GetEnumerator();
           HttpSessionState ss = HttpContext.Current.Session;
           if (HttpContext.Current.Session != null)
           {
               string sID = HttpContext.Current.Session.SessionID;
               if (ht.ContainsKey(sID))
               { }
               else
               {
                   HttpContext.Current.Response.ClearHeaders();
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
                   HttpContext.Current.Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP
                   HttpContext.Current.Response.Cookies.Clear();
                   HttpContext.Current.Response.Cookies["f758$jfp"].Expires = DateTime.Now;
                   HttpContext.Current.Response.Cookies["f758$jfp"].Values.Clear();
                   HttpContext.Current.Request.Cookies.Clear();
                   HttpContext.Current.Session.Clear();
                   HttpContext.Current.Session.Abandon();
                   FormsAuthentication.SignOut();
                   HttpContext.Current.Response.Redirect("Default.aspx");
               }
           }
           else
           { HttpContext.Current.Response.Redirect("PageAdminError.aspx"); }
 
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