DarthVader
DarthVader

Reputation: 55032

Session returning null even though i can see the values

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?

Upvotes: 0

Views: 764

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160892

UserId = Session["_UserId"] as string; 

Looks like the value for the key "_UserId" is not a string - hence you get null as result.

Upvotes: 3

Related Questions