0

私のmvc4アプリケーションでは、フォーム認証用のCookieを次のように作成します

public ActionResult Login(UserLogin user)
    {
        if (ModelState.IsValid)
        {
            bool res = System.Web.Security.Membership.ValidateUser(user.UserName, user.Password);

            if (res)
            {
                Utente utente = commonRepository.GetProfiloUtente(user.UserName);

                if (utente != null)
                {
                    Session["user"] = utente;
                }

                var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string userData = serializer.Serialize(utente);

                DateTime dataLavorativa = commonRepository.GetGiornoLavorativoPrecedente(utente.IDInterno);

                Session["data_lavorativa"] = dataLavorativa;


                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
          user.UserName, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), true, userData,
          FormsAuthentication.FormsCookiePath);



                string encTicket = FormsAuthentication.Encrypt(ticket);

                var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
                {
                    HttpOnly = true,
                    Secure = FormsAuthentication.RequireSSL,
                    Path = FormsAuthentication.FormsCookiePath,
                    Domain = FormsAuthentication.CookieDomain
                };

                // Create the cookie.
                Response.Cookies.Add(cookie);

                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", "Login data is incorrect!");
            }
        }
        return View("Index", user);
    }

これはFFoxで正常に動作します(ブラウザを閉じてから再度開くと)問題ありません.IEとChromeではログインページにリダイレクトされました....両方を確認しましたが、すべてセキュリティのレベルが低くなっています... Cookieを受け入れます...何か提案はありますか?ありがとう

4

0 に答える 0