Using session variable in authentication in asp.net mvc 4 application

I have an asp.net mvc4 application in which I have this class:

public class Internaute {
  public int Id { get; set; }
  public string Name { get; set; }
  public string Login { get; set; }
  public string Password { get; set; }
}

then when the user connects, I get his information, storing him in a session variable as follows:

Session["user"] = myInternaute;

And I used this data, for example, as follows:

@{
  Internaute myInternaute = (Internaute)Session["user"];
  string login = myInternaute.Login;
  string pwd = myInternaute.Password;
}

I check user authorization to access

Internaute myInternaute = (Internaute)Session["user"];
   if(myInternaute == null) return RedirectToAction("Index");

I have the following questions:

  • Is there a good way to navigate to a session variable?
  • Is there another idea to do this because the session was lost.
  • Does this idea have any advantages?

Thanks,

+4
source share
1 answer

?

, , , null, , , . , , ? .

, .

, , - . , - web.config.

- ?

, , , Internaute .

+3

All Articles