public class BaseController : Controller
{
public string UserId { set; get; }
public string AccessToken { set; get; }
private readonly IUnitOfWork _unit;
public BaseController(IUnitOfWork unit)
{
_unit = unit;
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
UserId = Session["_UserId"] as string;
AccessToken = Session["_AccessToken"] as string;
// ......
}
}
Even though AccessToken returns value. UserId is coming as null even though I can debug and see that there is a value in Session object.
I m setting them in session:
Session.Add("_UserId", user.Id);
Session.Add("_AccessToken", user.AccessToken);
What s going on?
Looks like the value for the key “_UserId” is not a string – hence you get
nullas result.