MembershipCreateUserException - The username supplied is invalid

前端 未结 6 1395
情书的邮戳
情书的邮戳 2021-02-09 09:43

On this line i am getting an exception -

OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);

System.Web.Security

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 10:18

    I was similarly looking for an explanation to this. I'm not sure I fully understand, but after experimentation, debugging, and watching intellitrace events, it seems CreateOrUpdateAccount is creating or updating an entry in the OAuthMembership table with just Provider, ProviderUserId, and UserId which is determined by querying [in my case] the UserProfile table based on this unique UserName. This way, if you call CreateOrUpdateAccount with a different provider and providerUserId, but the same username, then both provider sign ins are tied to the same user account in your app.

    I had to add a UserProfile before I could create/update the corresponding OAuthMembership record. In the VS template, it looked something like this:

    db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); 
    db.SaveChanges();
    
    OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
    

提交回复
热议问题