Accessing Session and IPrinciple data in a Master View in Asp.Net MCV
- by bplus
I currently have a abstract controller class that I all my controllers inherit from.
In my master page I want to be able to access some data that will be in Session and also the currently user (IPrinciple).
I read that I could use the contructor of by abstract base controller class, that is I could do something like
public BaseController()
{
ViewData["SomeData"] = Session["SomeData"];
ViewData["UserName"] = this.User.Identity.Name;
}
I could then access ViewData["UserName"] etc from my master page.
My problem is that both Session and User are null at this point.
Does anybody know of a different approach?
Thanks in advance.