Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. stop login if user has already loggedin with same userid

stop login if user has already loggedin with same userid

Scheduled Pinned Locked Moved ASP.NET
help
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vikas shukla
    wrote on last edited by
    #1

    Hi Sir, I want to add an facility to my application that if a user is login with user id Admin from pc-1 and then at the same time another user is login with same user id Admin from pc-2 then user on pc-1 should be log out and should have a message "You Have Been Signed Out.As Another User Has Signed In With Your UserID". please help me. one more issue is that if user does not logout and directly close the browser then user should be logout.

    B 1 Reply Last reply
    0
    • V vikas shukla

      Hi Sir, I want to add an facility to my application that if a user is login with user id Admin from pc-1 and then at the same time another user is login with same user id Admin from pc-2 then user on pc-1 should be log out and should have a message "You Have Been Signed Out.As Another User Has Signed In With Your UserID". please help me. one more issue is that if user does not logout and directly close the browser then user should be logout.

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      One way to do implement this functionality, that whenever a user login make an entry in DB as a loggedin user, once another user try to login with same user, allow to him for login but at the same remove the netry fro first user, and on evry postback check from whether the user has entry in db, if not then make him logout. Its better I think if a user has logged in from one pc then dont allow from other pc , just show a message a user has already loggedin.

      Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

      A V 2 Replies Last reply
      0
      • B Brij

        One way to do implement this functionality, that whenever a user login make an entry in DB as a loggedin user, once another user try to login with same user, allow to him for login but at the same remove the netry fro first user, and on evry postback check from whether the user has entry in db, if not then make him logout. Its better I think if a user has logged in from one pc then dont allow from other pc , just show a message a user has already loggedin.

        Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        Brij wrote:

        Its better I think if a user has logged in from one pc then dont allow from other pc , just show a message a user has already loggedin.

        Yes I am agree with you brij. Other wise its unnecessary hitting of DB on every post back which impact badly on performance.

        Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        V B 2 Replies Last reply
        0
        • B Brij

          One way to do implement this functionality, that whenever a user login make an entry in DB as a loggedin user, once another user try to login with same user, allow to him for login but at the same remove the netry fro first user, and on evry postback check from whether the user has entry in db, if not then make him logout. Its better I think if a user has logged in from one pc then dont allow from other pc , just show a message a user has already loggedin.

          Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

          V Offline
          V Offline
          vikas shukla
          wrote on last edited by
          #4

          thank u sir, i was doing the same as you are saying.and i am entering browser name also in my loginentry table(temp table). so that suppose if user login from ie browser and now he opens new ie and enter login page of application then user should not have login page because user has logged in once and it shows direct user home page.but if he enter login url in mozilla or any other browser then he should have login page. but at the same time if i am opening my login page from another system then again user home page is displaying.but it should be login page.

          A B 2 Replies Last reply
          0
          • A Abhijit Jana

            Brij wrote:

            Its better I think if a user has logged in from one pc then dont allow from other pc , just show a message a user has already loggedin.

            Yes I am agree with you brij. Other wise its unnecessary hitting of DB on every post back which impact badly on performance.

            Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

            V Offline
            V Offline
            vikas shukla
            wrote on last edited by
            #5

            hi sir, if you never mind sir.i want your yahoo id thank you very much sir.

            1 Reply Last reply
            0
            • A Abhijit Jana

              Brij wrote:

              Its better I think if a user has logged in from one pc then dont allow from other pc , just show a message a user has already loggedin.

              Yes I am agree with you brij. Other wise its unnecessary hitting of DB on every post back which impact badly on performance.

              Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

              B Offline
              B Offline
              Brij
              wrote on last edited by
              #6

              Yes. Its better

              Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

              A V 2 Replies Last reply
              0
              • B Brij

                Yes. Its better

                Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

                A Offline
                A Offline
                Abhijit Jana
                wrote on last edited by
                #7

                And I think this is quite well known problem for us ... ;) .. Account Locked : :laugh:

                Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                B 1 Reply Last reply
                0
                • B Brij

                  Yes. Its better

                  Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

                  V Offline
                  V Offline
                  vikas shukla
                  wrote on last edited by
                  #8

                  yes sir, you both are absolutely right.but please suggest me where i am wrong in my second post. and give your suggestion for this. thanks

                  1 Reply Last reply
                  0
                  • V vikas shukla

                    thank u sir, i was doing the same as you are saying.and i am entering browser name also in my loginentry table(temp table). so that suppose if user login from ie browser and now he opens new ie and enter login page of application then user should not have login page because user has logged in once and it shows direct user home page.but if he enter login url in mozilla or any other browser then he should have login page. but at the same time if i am opening my login page from another system then again user home page is displaying.but it should be login page.

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #9

                    Are you checking session variable properly ?

                    Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                    V 1 Reply Last reply
                    0
                    • A Abhijit Jana

                      Are you checking session variable properly ?

                      Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                      V Offline
                      V Offline
                      vikas shukla
                      wrote on last edited by
                      #10

                      yes sir, actually i am sending you my code behind. please consider this. using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Login_Bl; using message; using General_Bal; using ChecknetConnection; [Serializable] public partial class Default : System.Web.UI.Page { LoginBl objloginbl = new LoginBl(); GeneralBal objgeneral = new GeneralBal(); public static DataSet usr_val = new DataSet(); public static DataSet usr_val_usr = new DataSet(); protected void Page_Load(object sender, EventArgs e) { txtUserId.Focus(); if (Session["loginfailed"].ToString() == "1" ) { WebMsgBox.Show("You Have Been Signed Out.As Another User Has Signed In With Your UserID"); } string ses = Session.SessionID; if (usr_val.Tables.Count > 0) { if (usr_val.Tables[0].Rows.Count > 0) { string sess = usr_val.Tables[0].Rows[0]["sessionid"].ToString(); string expl = usr_val.Tables[0].Rows[0]["explorer"].ToString(); HttpBrowserCapabilities bro = new HttpBrowserCapabilities(); bro = Request.Browser; if (bro.Browser.ToString() == expl.ToString()) { Session["Roles"] = "Admin"; Session["customer"] = usr_val.Tables[0].Rows[0]["userid"].ToString(); Session["sessionid"] = usr_val.Tables[0].Rows[0]["sessionid"].ToString(); Response.Redirect("Admin/AdminHome.aspx"); } } } if (usr_val_usr.Tables.Count > 0) { if (usr_val_usr.Tables[0].Rows.Count > 0) { string sess = usr_val_usr.Tables[0].Rows[0]["sessionid"].ToString(); string expl = usr_val.Tables[0].Rows[0]["explorer"].ToString(); HttpBrowserCapabilities bro = new HttpBrowserCapabilities(); bro = Request.Browser; if (bro.Browser.ToString() == expl.ToString()) { Session["Roles"] = "User";

                      1 Reply Last reply
                      0
                      • V vikas shukla

                        thank u sir, i was doing the same as you are saying.and i am entering browser name also in my loginentry table(temp table). so that suppose if user login from ie browser and now he opens new ie and enter login page of application then user should not have login page because user has logged in once and it shows direct user home page.but if he enter login url in mozilla or any other browser then he should have login page. but at the same time if i am opening my login page from another system then again user home page is displaying.but it should be login page.

                        B Offline
                        B Offline
                        Brij
                        wrote on last edited by
                        #11

                        vikas shukla wrote:

                        but at the same time if i am opening my login page from another system then again user home page is displaying.but it should be login page.

                        You should also store the IP of the system along with the browser.So the you can check from which system user is trying to login.If request comes from another Ip then dont allow to be logged in. To get the IP of the client system, you can get using srever variables as Request.ServerVariables["REMOTE_ADDR"]

                        Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

                        V 2 Replies Last reply
                        0
                        • A Abhijit Jana

                          And I think this is quite well known problem for us ... ;) .. Account Locked : :laugh:

                          Cheers ! Abhijit Jana | MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                          B Offline
                          B Offline
                          Brij
                          wrote on last edited by
                          #12

                          yes :)

                          Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

                          1 Reply Last reply
                          0
                          • B Brij

                            vikas shukla wrote:

                            but at the same time if i am opening my login page from another system then again user home page is displaying.but it should be login page.

                            You should also store the IP of the system along with the browser.So the you can check from which system user is trying to login.If request comes from another Ip then dont allow to be logged in. To get the IP of the client system, you can get using srever variables as Request.ServerVariables["REMOTE_ADDR"]

                            Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

                            V Offline
                            V Offline
                            vikas shukla
                            wrote on last edited by
                            #13

                            thanks sir i tried your suggestion.but problem was same.if i am login from pc1 and at the same time i am trying to login from another pc then both are working while according to my requirement second should be on login page.that means both ip of the system are same is it possible? on the page load i am doing this. string ipaddress = Request.ServerVariables["REMOTE_ADDR"]; if (usr_val.Tables.Count > 0) { if (usr_val.Tables[0].Rows.Count > 0) { string ip = usr_val.Tables[0].Rows[0]["ipaddress"].ToString(); HttpBrowserCapabilities bro = new HttpBrowserCapabilities(); bro = Request.Browser; if(ip==ipaddress ) { if (bro.Browser.ToString() == expl.ToString()) { Session["Roles"] = "Admin"; Session["customer"] = usr_val.Tables[0].Rows[0]["userid"].ToString(); Session["sessionid"] = usr_val.Tables[0].Rows[0]["sessionid"].ToString(); Response.Redirect("Admin/AdminHome.aspx"); } } } } is there another way for take the ip of client system?

                            1 Reply Last reply
                            0
                            • B Brij

                              vikas shukla wrote:

                              but at the same time if i am opening my login page from another system then again user home page is displaying.but it should be login page.

                              You should also store the IP of the system along with the browser.So the you can check from which system user is trying to login.If request comes from another Ip then dont allow to be logged in. To get the IP of the client system, you can get using srever variables as Request.ServerVariables["REMOTE_ADDR"]

                              Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators

                              V Offline
                              V Offline
                              vikas shukla
                              wrote on last edited by
                              #14

                              hi sir, please try to understand my problem.and me some help.i am waiting for your help. thanks

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups