At login, I store user information logged into a cookie (name, password, etc ...)
How do I access this cookie and retrieve information from it?
For example, I want the name of the logged in user to appear in the upper bar, my logic would have to find the name already stored in the file and throw it in @Viewbag
determined in controller
, is correct this way of thinking? And what is the most aesthetic and correct way of doing this?
Here is the example of when you are authenticating:
[HttpPost]
public ActionResult Login(Login form, string retornarurl)
{
var usr = db.Usuario.FirstOrDefault(u => u.nome == form.nome);
if (usr == null || !usr.CheckPassword(form.passwordHash))
ModelState.AddModelError("nome", "Usuário ou senha estão incorretos ou não existe");
if (!ModelState.IsValid)
return View(form);
FormsAuthentication.SetAuthCookie(usr.nome, true);
return RedirectToAction("Index", "Admin" );
}