| |
Sign In
protected void Login1_LoggedIn(object sender, EventArgs e){ string correctUsername = Membership.GetUser(this.Login1.Username).Username; FormsAuthentication.SetAuthCookie(correctUsername , true);}
but this doesn't work because the "Username" property of the MembershipUser object does not collect its value from the AspNetDB SQL database like you would expect, instead it is filled with whatever you pass it when loading the user, this must be a bug but i'm not bothered trying to convince MS. instead, i came up with this solution below, to directly load the AspNetUser object from a Linq DataSource of the AspNetDb database (created using SqlMetal).
protected void Login1_LoggedIn(object sender, EventArgs e){ // correct the case of the username string Username = this.Login1.UserName; AspNetDb db = new AspNetDb(); MembershipUser memUser = Membership.GetUser(Username); // load the MembershipUser object to get the UserID Aspnet_User aspnetUser = db.Aspnet_Users.SingleOrDefault(z => z.UserId == new Guid(memUser.ProviderUserKey.ToString())); if(aspnetUser != null) Username = aspnetUser.UserName; FormsAuthentication.SetAuthCookie(Username, true);}
Remember Me