Accessing Session and IPrinciple data in a Master View in Asp.Net MCV
Posted
by bplus
on Stack Overflow
See other posts from Stack Overflow
or by bplus
Published on 2010-05-21T08:27:18Z
Indexed on
2010/05/21
8:30 UTC
Read the original article
Hit count: 246
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.
© Stack Overflow or respective owner