GetRolesForUser tries to get Roles on old username?

Posted by Xaisoft on Stack Overflow See other posts from Stack Overflow or by Xaisoft
Published on 2010-03-24T22:50:49Z Indexed on 2010/03/24 22:53 UTC
Read the original article Hit count: 355

Filed under:
|
|

I have a section on a page where a user can change their username. This is basically the code for that:

user.UserName = txtNewUserName.Text;
user.Save();

user is a class in my dbml and Save calls SubmitChanges on the data context.

The name is changed in the database, so when it calls the following method, it fails because it is trying to get the user with the old username instead of the one that is in the database now.

public override string[] GetRolesForUser(string username)
{
    return dc.Users.Where(u => u.UserName== username)
                   .SingleOrDefault().Roles
                   .Select(r => r.RoleName).ToArray<string>();
}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#