6
My scenario is as follows. I have an MVC 4 application. In my controller I check the logged in user and password. (I think) I put the user data in a session after the data is checked and correct.
My pages are cshtml (Razor). And I have a master page that will use the data from Session to show the logged in user for example.
If the login data is not correct the session will be empty and I will redirect to the login page.
Doubts:
- How to open and close the session?
- How to set downtime to close it?
- What it takes for the system to only allow direct access through Urls after login and Session active.
My Login Screen Action after sending the data:
[HttpPost]
public ActionResult Index(UsuarioDTO dto)
{
UsuarioDTO ValidarLogin = null;
UsuarioDTO usuario = new UsuarioDTO();
usuario.Login = dto.Login;
usuario.Senha = dto.Senha;
negocio = new AeroJetNEGOCIO();
try
{
ValidarLogin = negocio.Login.LogarUsuario(usuario);
usuario = ValidarLogin;
Session["usuarioLogado"] = usuario;
return RedirectToAction("Index", "CadastroCliente");
}
catch (Exception e)
{
ViewBag.classe = "alert";
ViewBag.msg = e.Message;
return View();
}
}
NOTE: This part I include I don’t even know how it behaves. It was just an attempt.
This screen redirects to another Action from another Controller that is a screen for an already logged in user.
public ActionResult Index()
{
return View();
}
NOTE: I don’t know if I should put some code to validate Session ai. I need help on this part.
If you need the cshtml of the master page or the page that enters after login I post.
I believe that this question I answered solve your problem well.
– Leonel Sanches da Silva
I will give a studied in your solution to try to implement. Thank you.
– Joao Paulo