Check if user is already logged in asp.net website

后端 未结 6 1658
不思量自难忘°
不思量自难忘° 2021-01-25 20:32

I am developing a website where in user is required to login to the system to be able to use it. The current functionality is: When user enters username and password, a check is

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 21:02

    May be the old answers were worth observing at that time. However, I have currently resolved the problem using User.Identity.IsAuthenticated. I have EntityFramework 6 and using Dot Net Framework 4.7.2 and MVC 5. You need to set FormsAuthentication.SetAuthCookie(PrimaryKey, false); when user is loggedIn. Here, PrimaryKey is the key that you can use throughout the session for identification of the user using User.Identity.Name. Also, when user log out of the application, you will call FormsAuthentication.SignOut(); This actually saves the information in the browser cookie so that you can reuse the information.

提交回复
热议问题