title: Context.User doesn't persist between page requests in MVC - best approach?
body: <p>Excuse me if this has been asked already on SO I've looked around the forums and can't find the specific answer. I am developing an intranet site and I am setting a GenericPrincipal to Context.User. This takes place in the Global.asax before the default controller loads. The controller uses a custom authorize attribute to manage which users can see what content.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Http;
  using System.Web.Mvc;
  using System.Web.Optimization;
  using System.Web.Routing;
  using System.Security.Principal;
  
  namespace IntranetTest
  {
      // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
      // visit http://go.microsoft.com/?LinkId=9394801
  
      public class MvcApplication : System.Web.HttpApplication
      {
          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
  
              WebApiConfig.Register(GlobalConfiguration.Configuration);
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
  
              DAL.IME_IMechEHubUsers IME_IMechEHubUsers = new DAL.IME_IMechEHubUsers();
              List&lt;string&gt; Roles = IME_IMechEHubUsers.GetRoles();
              Models.User User = IME_IMechEHubUsers.GetUser();
  
              GenericPrincipal userPrincipal = new GenericPrincipal(new GenericIdentity(User.RoleName), Roles.ToArray());
  
              Context.User = userPrincipal;
          }
      }
  }
  </code></pre>
  
  <p>My problem is when I make a second GET request by clicking on one of the links on the page it no longer knows the role of user. It has been overridden by the users network identity.</p>
  
  <p><img src="https://i.stack.imgur.com/wg7qZ.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/jguYP.png" alt="enter image description here"></p>
  
  <p>I am a bit stuck with how to authorize users in an intranet application. The database used to store the roles and the users is the aspnet membership tables. But they are just standard tables and the question is more how to persist a users role between requests using httpcontext.user.</p>