Currently I have a problem that I need to solve to avoid duplicate code in my software. I would like that by the time the login was performed, the system would store some information so that I did not have to go all the time in the query database. I would need to store, for example, information from two classes:
USER
public class User
{
public Guid Id { get; set; }
public String Name { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
}
SCHOOL
public class School
{
public Guid Id { get; set; }
public String Name { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
public int Code { get; set; }
}
I constantly use information from these two in my software, and currently every time I load them from the database. So I would like to know if there is a way for me to store the information at the time I log in so that I do not have to query the database. My login code:
if (user != null)
{
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(new FormsAuthenticationTicket(login.Email.ToLower(), false, 60))));
//Store school and user information here.
return RedirectToAction("Dashboard", "Home", new { area = "" });
}
Is there any way to store this information and retrieve them the same as the User.Identity.Name
, for example?