title: Session Variables Is Null after Redirecting to a New Page
body: <p>MVS 2012
  SQL Server 2008 R2</p>
  
  <p>I have an object that is being store in a session using a session wrapper. During login, I initialize the object and set the session appropriately. After authenticating the user, I redirect the user to the user index page. The user is redirected to the index page, but the session variable is not null. I am not sure why that is happening. Here is a sample code of what I am doing. </p>
  
  <p>Here is my web config setting. <strong>If I comment out this web config section and run the application again, it worked fine.</strong></p>
  
  <pre><code>&lt;sessionState mode="SQLServer" allowCustomSqlDatabase="true" timeout="60" cookieless="false" sqlConnectionString="Data Source=(****);Initial Catalog=data1;User ID=****;Password=****;Integrated Security=True" /&gt;
  </code></pre>
  
  <p>This is the object that is wrapped in the session</p>
  
  <pre><code> public class CurrentRequest
   {
     public int UserId { get; set; }
     public string Role { get; set; }
   }
  </code></pre>
  
  <p>here is the session wrapper</p>
  
  <pre><code> public static CurrentRequest currentRequest
   {
     get
     {
       if (HttpContext.Current.Session["request"] != null)
       {
         return (CurrentRequest)HttpContext.Current.Session["request"];
       }
       else
       {
         return null;
       }
     }
     set
     {
       HttpContext.Current.Session["request"] = value;
     }
   }
  </code></pre>
  
  <p>Here I am checking the role and redirect the user to the appropriate page     </p>
  
  <pre><code>CurrentRequest currentRequest = new CurrentRequest();
  SessionWrapper.currentRequest = currentRequest;
  int userId = login.GetUserId(model.UserName, true);
  SessionWrapper.currentRequest.UserName = model.UserName;
  string[] roles = Roles.GetRolesForUser(model.UserName);
  if (roles.Count() &gt; 0)
  {
    string aRole = roles[0];
    switch (aRole)
    {
      case "Admin":
        SessionWrapper.currentRequest.Role = aRole;
        SessionWrapper.currentRequest.UserId = userId; 
  .
  .
  </code></pre>
  
  <p>the sessions variables above are set properly and I am redirecting the user to the Users' Index page</p>
  
  <pre><code>return RedirectToAction("Index", "Users");
                      case "User":
  </code></pre>
  
  <p><strong>On the Users Controller, I am checking to see if this user is an admin or not, but the session variable SessionWrapper.currentRequest is null</strong></p>
  
  <pre><code>if (SessionWrapper.currentRequest.Role == "Admin")
  {
    users = db.UserRepository.GetAll();
  }
  </code></pre>
  
  <p>What I am doing wrong here?</p>