asp.net mvc - Passing UserId with UserName in MVC4 FormsAuthentication -


as not have userid in formsauthentication want pass it.here code

public bool isvalid(string email, string password)     {         bool isvalid = false;         var user = db.users.firstordefault(u => u.email == email);          if (user != null)         {              if (user.password == encryptpassword(password))             {                 isvalid = true;              }          }         return isvalid;     }       if (user.isvalid(user.email, user.password))             {                  formsauthentication.setauthcookie(user.email + "|" + user.id, true);                 return redirecttoaction("index", "testvaliduser");             } 

now issue user.id 0 in formsauthentication.setauthcookie()

how can set it?

int userid=0;   public bool isvalid(string email, string password,out int userid)     {      if (user.password == encryptpassword(password))             {                 isvalid = true;                 userid= user.id             } }  if (user.isvalid(user.email, user.password,userid))             {                  formsauthentication.setauthcookie(user.email + "|" + userid, true);                 return redirecttoaction("index", "testvaliduser");             } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -