c# - Storing user data after authentication with MVC4 -
i creating simple login using asp.net mvc4 / razor. need custom logic, here's have far:
public class user { [required] [display(name = "user name")] public string username { get; set; } [required] [datatype(datatype.password)] [display(name = "password")] public string password { get; set; } public int userid { get; set; } public datetime lastlogin { get; set; } public bool isvalid(string username, string password) { if(mycustomlogic.isvaliduser(username, password)){ // set other variables return true; } else { return false; } } }
in controller:
public actionresult login(models.user user) { if (modelstate.isvalid) { if (user.isvalid(user.username, user.password)) { formsauthentication.setauthcookie(user.username, true); // line in question } } return view(user); }
i want store model.user
can accessed in view persistently. storing in session
variable seems obvious choice, expire independently of authentication cookie
.
i think you're asking, how should store user subsequent requests? convention create own subclass of iprincipal
can store whatever want, , set httpcontext.current.user
instance of this. this question has full examples.
Comments
Post a Comment