I have problem in my LoggedUser
property which is made back in the days with .Net Framework (standart). Now I want to fix LoggedUser
, but using Asp.Net Core
. The error that I got is that I can't use HttpContext.Current.Session
it underline Current
. Who could help me to fix this and save the same structure of code. Thank You!
public class AuthenticationService
{
public static bool IsLogged
{
get
{
return LoggedUser != null;
}
}
public static User LoggedUser
{
get
{
return (User)HttpContext.Current.Session[typeof(AuthenticationService).Name];
}
private set
{
HttpContext.Current.Session[typeof(AuthenticationService).Name] = value;
}
}
public static void AuthenticateUser(string username, string password)
{
UserRepository userRepo = new UserRepository();
User user = userRepo.GetAll(u => u.Username == username && u.Password == password).FirstOrDefault();
if (user != null)
LoggedUser = user;
}
public static void LogOut()
{
LoggedUser = null;
}
}