title: Acessing Value from Global Variable in MVC
body: <p>Hi we developing web application using mvc4 and jquery mobile. In our each controller we created user session like below.</p>
  
  <p>public class HomeController : BaseController
  {
      private static User CurrentUser;</p>
  
  <pre><code>    public ActionResult Index(string name)
      {
         CurrentUser = (User)Session["CurrentUserSession"];
         return View();
      }
  
     public ActionResult UserDetaiks()
      {
         string username = CurrentUser.UserFName;
         return View()
       }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>            Above we created object for User model and assigned session value in index method. But the value in CurrentUser is lost once i entered UserDetails. So i Used static while creating object. My question is it correct? or anyother way is there. Please guide me.
  </code></pre>
  
  <p>Thanks guys One more Doubt,</p>
  
  <p>I used below code in form authenticate.</p>
  
  <pre><code> HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                  if (authCookie != null)
                  {
  
                      FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
  
                      var s = new System.Web.Script.Serialization.JavaScriptSerializer();
                      User obj = s.Deserialize&lt;User&gt;(authTicket.UserData);
  
                      UserInformation CurrentUser = new UserInformation(obj.UserID);
                      CurrentUser.UserId = obj.UserID;
                      CurrentUser.FirstName = obj.UserFName;
                      CurrentUser.LastName = obj.UserLName;
                      CurrentUser.roles = obj.SecurityGroupName;
                      CurrentUser.DefaultWarehouseId = obj.DefaultWhseIdentity; eg:14
                      HttpContext.Current.User = CurrentUser;
  
                  }
  
  
  
  **Here User can Change CurrentUser.DefaultWarehouseId  later like CurrentUser.DefaultWarehouseId = 16. but when i leave the method. It again getting value 14. Now i can code so CurrentUser.DefaultWarehouseId will be 16 through out app one i changed, Please guide me.**
  </code></pre>