0

I'm using forms authentication to log users into an ASP.NET application. My code is like this.

        if (txtPassword == correctPassWord)
        {
            FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(1, txtUserId.Text.Trim(), DateTime.Now, DateTime.Now.AddMinutes(30), false, "");
            string cookiestr = FormsAuthentication.Encrypt(tkt);
            HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
            ck.Path = FormsAuthentication.FormsCookiePath;
            Response.Cookies.Add(ck);
            Session["UserId"] = txtUserId.Text.Trim();
            Response.Redirect("~/Default.aspx");
         }

I need to find the user IDs who are logging in into the system at any given time. Is there a way to find out which users are using the application without saving the user to the database.

user3930306
  • 25
  • 1
  • 7
  • You would need a database -- how would you even have the concept of an 'ID' without a table in a database? – Obsidian Age May 09 '18 at 03:56
  • I need to find all the authenticated uses at any given time. I don't like to write the authenticated users to a data table at the time they are login and remove it when they log out from the application. – user3930306 May 09 '18 at 04:10
  • Well store the information in memory - but remember, as default an asp.net application will be restarted after 20 minutes and all of these in memory informations are lost – Sir Rufo May 09 '18 at 04:13
  • 2
    The answer that you are looking for doesn’t exist. You are storing identity in cookies stored I the client. Let’s say that a client clears its cookie. It is no longer logged in because it would have to log in again to access the site. How could the server possibly know that the cookie is gone on the client. I think that you are expecting clients to log out when done, but that is a probably a rare occurrence. – Mike Wodarczyk May 09 '18 at 04:20
  • 1
    Possible duplicate of [Check if user is already logged in asp.net website](https://stackoverflow.com/questions/30475914/check-if-user-is-already-logged-in-asp-net-website) – Lucifer May 09 '18 at 04:36

0 Answers0