title: How to get User.Identity.Name from a controller?
body: <p>I want to have some viewData info across all my views so I am following this tutorial</p>
  
  <p><a href="http://www.asp.net/LEARN/mvc/tutorial-13-cs.aspx" rel="nofollow noreferrer">http://www.asp.net/LEARN/mvc/tutorial-13-cs.aspx</a></p>
  
  <p>So I made my own applicationController but I need to get the UserName from the user.</p>
  
  <p>Yet when I do this "HttpContext.User.Identity.Name" in the constructor it is always null. I am not sure why though.</p>
  
  <p>Thanks</p>
  
  <p>Ok the base thing did the trick.</p>
  
  <pre><code>  protected override void Initialize(RequestContext requestContext)
      {
          base.Initialize(requestContext);
          Guid userId = coursesS.GetUserId(HttpContext.User.Identity.Name);
      }
  </code></pre>
  
  <p>So that seems to work. The only thing now is it seems to go through this twice. Like I log in and it seems to do the this twice. I am guessing since this is like the equivalent of putting that code in every action. When I am loading up all these partial view on my site by calling them in my controller it does this.</p>
  
  <p>So many I should cache it but I am not sure how though.</p>