Hi lingers,
The return type of SetString is void and you are trying to assigned to the CreatedBy property.
So first you need to set the Session and then to get the Session using GetString method and assign it.
Refer the modified code.
public IActionResult login(string userID, string password)
{
UserDetail usr = new UserDetail();
// Set Session.
HttpContext.Session.SetString("CurrUSerID", userID);
usr.UserID = userID;
// Get Session value.
usr.CreatedBy = HttpContext.Session.GetString("CurrUSerID");
if (!ModelState.IsValid)
{
return View();
}
UserDetail erp = objBL.GetLogin(userID, password);
if (erp != null)
{
// Valid User.
return RedirectToAction("Create");
}
else
{
// Invalid UserId Or Password.
ViewBag.Error = "Login failed";
return View();
}
}
For more details on Get and Set Session refer Get and Set Session object (variable) in ASP.Net Core.