Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have count the number of online user to the web server. i have created the username & assign the password to individual computer then using this user name user can access the main page & after login user i have add the username ,session ID,ip address in datatable. if i user already connected from another computer then same user access the information from another computer then user first disconnect the alredy conected from current computer using kill the session from sessionID . then another computer fuctionality automatically disbled to user then user can start the new session for current computer.

how to kill the session from Unique sessionID & disbled the all fuctionality of the another computer user ?
Posted

Varushali,
You can try this:-

call 'getSingleLogin("UserName'")' Method Before Login Process.



void getSingleLogin(string username)
   {
       if (Cache["_users"] == null)
       {
           Hashtable ht = new Hashtable();
           ht.Add(username, Request.UserHostAddress + "~" + Session.SessionID);
           Cache["_users"] = ht;
       }
       else
       {
           Hashtable ht = (Hashtable)Cache["_users"];
           if (ht.Contains(username))
           {
               checkUserSession(username);
           }
           else
           {
               ht.Add(username, Request.UserHostAddress + "~" + Session.SessionID);
               Cache["_users"] = ht;
           }
       }
   }

C#
private void checkUserSession(string userDetails)
    {
        if (!string.IsNullOrEmpty(userDetails))
        {
            string str = ((Hashtable)(Cache["_users"]))[userDetails].ToString();
            string[] _str = str.Split('~');
            if (Request.UserHostAddress.Trim() != _str[0].Trim())
            {
                Session.Contents.Remove(_str[1]);
            }
        }
    }
   
v2
My understanding of the question:

you need someone to log in to access the site. now unless this guy logs off on one should be able to login and access the site.

If this is correct understanding then using session is perhaps not the right choice. use application to store the username. if the application["user"] is not null don't let anyone login and when the user logs off set this to null so that others can login.
   
Comments
vrushali katkade 28-Mar-12 4:41am
   
not like this i have number user can login to access the site but the same user can not access the site same time.when alrady connectd user access the site from another computer then user first disconnect the already connected session then start the new session . if session get remove or kill then user can not access the any fuctionality of the website

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