3
In login, I store user information logged in to a cookie (name, password, etc...)
How do I access this cookie and redeem information from it?
For example, I want the name of the logged in user to appear in the top bar, by my logic I would have to find the name that is already stored in the file and play it in a @Viewbag determined in the controller, is this way of thinking correct? And what is the most aesthetic and correct way of doing this action?
Follow the example of when you authenticate:
[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" );
}
You are using an authentication provider such as Membership or Identity?
– Leonel Sanches da Silva
I don’t think so. I created a repository for authentication myself, which will later be done through a custom form.
– Matheus Silva
You can put a part of his code in your question?
– Leonel Sanches da Silva
In vdd it is in the same controller...
– Matheus Silva