'Session Value Mismatch in ASP.Net Core MVC

After login to the application, we are setting a value in a session variable in the Login Controller as below:

public ActionResult Login(LoginInfo loginInfo, string returnUrl)
{
    //...
    HttpContext.Session.SetString(SessionKeyPID, 226617); //PersonId - 226617
}

But later when we try to get the same in another controller with below:

[HttpGet]        
public JsonResult GetDetails()
{
    int person = Convert.ToInt32(HttpContext.Session.GetInt32(SessionKeyPID));
}

I'm getting different value like 842151478 instead of having 226617. Why I'm not getting same value. Can I get the same value?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source