Amr Elgarhy
Amr Elgarhy

Reputation: 68972

How to use MongoDB.AspNet.Identity with WebApi2

I am building a WebApi2 project and wanted to use mongodb as a backend and I found MongoDB.AspNet.Identity package, I used it before in MVC5 website and it worked well, but after installing in the WebApi project I got an error: enter image description here

Error 1 The type or namespace name 'IdentityUserLogin' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs

How to fix that? or it is impossible to use MongoDB.AspNet.Identity package with WebApi2 projects?

Upvotes: 3

Views: 2247

Answers (2)

user2849973
user2849973

Reputation: 21

You mean replace,

user.Logins.Add(new IdentityUserLogin 
{
  LoginProvider = externalLogin.LoginProvider,
  ProviderKey = externalLogin.ProviderKey
});

to

user.Logins.Add(new UserLoginInfo(
        externalLogin.LoginProvider,
        externalLogin.ProviderKey
));

Upvotes: 2

Radosław Gers
Radosław Gers

Reputation: 126

Change every occurence of IdentityUserLogin to UserLoginInfo. Furthermore change

user.Logins.Add(new UserLoginInfo
        {
            LoginProvider = externalLogin.LoginProvider,
            ProviderKey = externalLogin.ProviderKey
        });

to

user.Logins.Add(new UserLoginInfo(
            externalLogin.LoginProvider,
            externalLogin.ProviderKey
        ));

Should work now.

Upvotes: 7

Related Questions