I was trying to access the User object in Controller constructor so that I can get the logged in username in the constructor, but the User object was coming as null and as a result I was getting Null reference exception.Solution
The solution of this problem is to create an override method of Initialize by passing RequestContext object.
public class ChartsController : Controller
string _userName = string.Empty;
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
_userName = requestContext.HttpContext.User.Identity.Name;
and then we can access the User object. The same is applicable for Session or any other object inside HttpContext.
Hope this helps.