title: My membership provider - how to find current user
body: <p>I use ASP.NET, MVC with my own DB.
  I tried to implement my own membership provider because i wanted to use my DB table "users".</p>
  
  <p>But now i am confused:
  I have registration and i have Login page that works.
  But after i Login how other controllers and pages can know what is the current user Id is logged in?</p>
  
  <p>Functions that i implemented in my membership provider:</p>
  
  <pre><code>public class MyMembershipProvider : MembershipProvider
      {
      private ManagerdBEntities1 db = new ManagerdBEntities1();
          //
          // Properties from web.config, default all to False
          //
          private string _ApplicationName;
  
          private bool _EnablePasswordReset;
          private bool _EnablePasswordRetrieval = false;
          private bool _RequiresQuestionAndAnswer = false;
          private bool _RequiresUniqueEmail = true;
          private int _MaxInvalidPasswordAttempts;
          private int _PasswordAttemptWindow;
          private int _MinRequiredPasswordLength;
          private int _MinRequiredNonalphanumericCharacters;
          private string _PasswordStrengthRegularExpression;
          private MembershipPasswordFormat _PasswordFormat = MembershipPasswordFormat.Hashed;   
  
          private string GetConfigValue(string configValue, string defaultValue)
          public override void Initialize(string name, NameValueCollection config)
          public override string ApplicationName
          public override bool ChangePassword(string username, string oldPassword, string newPassword)
          public override bool ChangePasswordQuestionAndAnswer(string username,
                                                         string password,
                                                         string newPasswordQuestion,
                                                         string newPasswordAnswer)
          public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
  
      public override MembershipUser GetUser(string username, bool userIsOnline)
      public override string GetUserNameByEmail(string email)
       public override string ResetPassword(string username, string answer)
      public override bool EnablePasswordReset
  public override bool EnablePasswordRetrieval
  public override int MaxInvalidPasswordAttempts
  public override int MinRequiredNonAlphanumericCharacters
  public override int MinRequiredPasswordLength
  public override int PasswordAttemptWindow
  public override MembershipPasswordFormat PasswordFormat
  public override string PasswordStrengthRegularExpression
  public override bool RequiresQuestionAndAnswer
  public override bool RequiresUniqueEmail
  public override bool ValidateUser(string username, string password)
  </code></pre>
  
  <p><strong>My User model:</strong></p>
  
  <pre><code>public partial class User
      {
              private ManagerdBEntities1 db = new ManagerdBEntities1();
  
          public MembershipUser CreateUser(string username, string password, string email)
          public static void SendEmailThroughGmail(string messageBody, string emailTo)
          public User FindUser(string username)
          public string GetUserNameWithEmail(string email)
          public MembershipUser GetUser(string username)
         private static string CreateSalt()
         public bool ValidateUser(string username, string password)
                private static string CreatePasswordHash(string pwd, string salt)
  </code></pre>
  
  <p>**</p>
  
  <ul>
  <li>And this is user fields:</li>
  </ul>
  
  <p>**</p>
  
  <pre><code> public int Id { get; set; }
          public string UserName { get; set; }
          public string Email { get; set; }
          public string Password { get; set; }
          public int PermissionsId { get; set; }
          public int MainGroupId { get; set; }
          public int MinorGroupId { get; set; }
          public string PasswordSalt { get; set; }
          public string Comments { get; set; }
             [DataType(DataType.Date)]
          public System.DateTime CreateDate { get; set; }
          public Nullable&lt;System.DateTime&gt; LastModifiedDate { get; set; }
          public System.DateTime LastLoginDate { get; set; }
          public string LastLoginIP { get; set; }
          public bool IsActivated { get; set; }
          public bool IslockedOut { get; set; }
          public System.DateTime LastLockedoutDate { get; set; }
          public string LastLockedOutReason { get; set; }
          public string NewPasswordKey { get; set; }
          public Nullable&lt;System.DateTime&gt; NewPasswordRequested { get; set; }
          public string NewEmail { get; set; }
          public string NewEmailKey { get; set; }
          public Nullable&lt;System.DateTime&gt; NewEmailRequested { get; set; }
  
          public virtual Permission Permission { get; set; }
          public virtual ICollection&lt;Task&gt; Tasks { get; set; }
          public virtual UserGroup UserGroup { get; set; }
          public virtual UserGroup UserGroup1 { get; set; }
  </code></pre>