クッキーにアクセスしてユーザーとパスワードを取得し、ログインビューのテキストボックスに設定する必要があります。 "ログインに成功した後のセッションとクッキーのC#MVC 5フォーム認証がサインアウトするとチケットクッキーが消去されます
ログオフの方法
public ActionResult LogOff()
{
//Session.Abandon();
// sign out.
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Login");
}
初期化。ログインビュー 私は私が最初にログアウトしてからクッキーにアクセスしようとする問題を抱えているが、私は実行するので、それはnullを返しますの
private void InitializeSessionVariables(AgentDTO user)
{
// SessionModel.AgentId = user.ID;
Response.Cookies.Clear();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,user.MobilePhone,DateTime.Now,DateTime.Now.AddDays(30),true,"",FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
// Create the cookie.
HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Name of auth cookie (it's the name specified in web.config) // Hashed ticket
authenticationCookie.Expires = DateTime.Now.AddDays(365);
// Add the cookie to the list for outbound response
Response.Cookies.Add(authenticationCookie);
}
アクション結果「FormsAuthentication.SignOut();」彼は上をクリックミーの文書readyイベントに値
とログインページ上に設定するためのチェックボックス
使用
localStorage.setItem("UserName", "Smith");
を覚えている場合は、ストアのユーザー情報にはJavaScriptを使用することができます
public ActionResult Index(LogonDTO model, string message = null, string reason = null)
{
if (SessionModel.AgentMobilePhone != null) return RedirectToAction("Index", "Home");
if (reason != null) message = "Su sessión ha expirado. Vuelva a loguearse.";
ViewBag.Message = message;
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
model.Username = authTicket.Name;
//model.Password = "in progress..."
}
return View(model);
}
https://support.microsoft.com/en-us/help/910443/understanding-the-forms-authentication-ticket-and-cookie、 'FormsAuthentication.SignOut();'が削除されます。いずれの場合もクッキー私は、永続的なクッキーの場合は、 'FormsAuthentication.SignOut();'を全く呼び出さないと仮定します。 – Patrick
そうですね、私の場合はクッキーを決してすべきではありませんか? – Necroimix
私は 'FormsAuthentication.SignOut();'は、ユーザがまだチケット/クッキーを持っていてもあなたのサーバにオープンセッションがない場合にのみ使用すべきだと思います。これにより、ユーザーのブラウザからチケットが削除され、再度「ログイン」する必要があります。 – Patrick