0

I have a application where to access the database user has to be in a session. When the user logs in, in browser he/she gets authenticated and session starts. Here is an example

[HttpPost]
[AllowAnonymous]
public ActionResult CustomLogin(LoginModel login)
{
    using (var loginsSession = SoSession.Authenticate(login.Username, login.Password))
    {
        var x = 0;
    }

    return null;
}

Problem Everytime user gets out of this controller's login function, the session expires. If the user wants to access database again, I need to create new session but the problem is I don't know how to store the username and password so that I don't have to ask user to login again and again. Is there some smart way to store username and password somewhere so that I can use it till the user logs out from the browser?

Cybercop
  • 8,475
  • 21
  • 75
  • 135
  • You have to implement cookies for that. http://stackoverflow.com/questions/3140341/how-to-create-persistent-cookies-in-asp-net – CodeXerox Jan 10 '14 at 07:58
  • For basics of cookies: http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx – CodeXerox Jan 10 '14 at 08:01

1 Answers1

0

I'm not sure: You are using session in using (){} statement. When you get out of login controller, The using statement calls the Dispose method on the Session.

Hope this help.

lmt1608
  • 84
  • 9
  • actually that could be an option to not use `Using(){}` and dispose the session when user logs out from browser. But I wanted to know if there is some way to save username and password somewhere so that i can access it later – Cybercop Jan 10 '14 at 08:07
  • You can use the cookies to store username and password, but it has problem about the security. – lmt1608 Jan 10 '14 at 08:14