5
In my project I have an authentication module and logout. But I wanted when the user logged in I’d get the id of it so that I would show the information concerning the login of it. Like a view details. But that the user who logged in, had a link and in that link had the id so that when he clicked on the details page showed the information and if you want to edit it is also possible to take this id.
Namely, I’m using custom authentication. So how can I do this ?
I’ll put my actions of login and logout:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(String Login, String Senha)
{
//verificando login pelo usuario do banco de dados ...
Usuario login = db.Usuarios.Where(x => x.Login == Login && x.Senha == Senha).FirstOrDefault();
if (login != null)
{
FormsAuthentication.SetAuthCookie(Login, false);
Session.Add(".PermissionCookie", login.Perfil);
return RedirectToAction("Index", "Home"); //pagina padrao para todos os usuarios...
}
return RedirectToAction("Index");
}
public ActionResult Sair()
{
FormsAuthentication.SignOut();
Session.Remove(".PermissionCookie");
return RedirectToAction("Index");
}
Gypsy how can I put this user id to a link so I can redirect the user to a detail page and edit the data ? Type the Manager of Identity. This link would be on partial that would be rendered in _Layout. Leaving so that ta ai that you did, appearing the user name.
– Érik Thiago
@Érikthiago How do you want the link format? This influences how the Controller call will be built.
– Leonel Sanches da Silva
Type, I wanted the link to show the name of the user and when clicking it was redirected to a page that has the details related to it and this page has a link to edit its data as well.
– Érik Thiago
My answer and @Diegozanardo’s answer already do that. What would be missing from them?
– Leonel Sanches da Silva
But what happens is that the Id user this way you passed me... How would I do ?
– Érik Thiago
You can take the user ID internally. There’s no reason for it to come in the URL or any other device.
– Leonel Sanches da Silva
How would I do that then ? Because I wanted the link to recognize the user id so that it could change its data and see the details too
– Érik Thiago
The user is yours or someone else’s?
– Leonel Sanches da Silva
The user who is logged in to the application
– Érik Thiago
As I told you, and the answers show well, don’t need. You just need to make use of the context and bring the user identification in-house, using
User.Identity.Name
.– Leonel Sanches da Silva