Search code examples
asp.netasp.net-membership

How to check if user is logged in and has a active session in ASP.NET?


Is it possible to check if a user is logged in and has a active session in ASP.NET using only the username? I need some sort of service to return true/false based on username as input. I don't have access to Page.User.Identity.IsAuthenticated


Solution

  • yes it is possible. Once the user has logged on set a session variable I like to make a class for Users then turn it into a session variable:

    eg:

       userData loggedIn = new userData(username, email);
       Session["User"] = loggedIn
    

    Then when I'm checking if somebody is logged in I use something in the page load like

        if (Session["User"] != null);