MembershipCreateUserException - The username supplied is invalid

前端 未结 6 1409
情书的邮戳
情书的邮戳 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:14

    For me, this error happened in my Seed override. As rgnever pointed the username not existing is referring to the UserProfile table. To fix it the User and Account have to be created first before creating the OAuth.

    So, instead of my Seed override ONLY calling:

    membership.CreateOrUpdateOAuthAccount(provider, providerid, providername);
    

    it now calls:

    membership.CreateUserAndAccount(providername, null);
    membership.CreateOrUpdateOAuthAccount(provider, providerid, providername);
    

    Note: The null password means the user cannot log in via a login form because the supplied password will never be null. I'm only using OAuth so it's not an issue for me.

提交回复
热议问题