Beispiel #1
0
 public ActionResult Index()
 {
     if (Request.Cookies[".ad"] == null)
     {
         if (SessionCheckingServices.userID == null)
         {
             return(RedirectToAction("Login"));
         }
         else
         {
             return(View());
         }
     }
     else
     {
         //Kiểm tra cookie lấy id của user để lấy thông tin user
         DataContext db                   = new DataContext();
         HttpCookie  authCookie           = Request.Cookies[FormsAuthentication.FormsCookieName];
         FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
         var getUserIDFromCookie          = int.Parse(ticket.Name);
         var getUser = (from user in db.Users where user.User_ID == getUserIDFromCookie select user).FirstOrDefault();
         SessionCheckingServices.Session(getUser.User_ID, getUser.avatar, getUser.userName, getUser.password, getUser.role);
         return(View());
     }
 }
Beispiel #2
0
 public ActionResult _PartialUserInformation()
 {
     if (Request.Cookies[".ad"] != null)
     {
         //Kiểm tra cookie lấy id của user để lấy thông tin user
         DataContext db                   = new DataContext();
         HttpCookie  authCookie           = Request.Cookies[FormsAuthentication.FormsCookieName];
         FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
         var getUserIDFromCookie          = int.Parse(ticket.Name);
         var getUser = (from user in db.Users where user.User_ID == getUserIDFromCookie select user).FirstOrDefault();
         SessionCheckingServices.Session(getUser.User_ID, getUser.avatar, getUser.userName, getUser.password);
         return(PartialView("_PartialUserInformation"));
     }
     return(PartialView("_PartialUserInformation"));
 }