Problems to directly access the indentity tables with web api through the context.?


As I can access the tables directly, it is with the identity that I can access all the procedures as an example:

var user = await UserManager.FindByNameAsync(userName);

All those methods I use, but I see the need to call the context to bring me a user list and the context does not bring me any table _ctx.AspNetUsers I instantiate the context but it does not bring me the table. I'm doing it in a web api

asked by Erwing 23.05.2016 в 01:10

1 answer


I think your problem is that Webapi by default does not have the UserManager configured, so you should initialize it. The solution is from here: link

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.DataProtection;
using Owin;

namespace Identity_PasswordPolicy
    public partial class Startup
        // For more information on configuring authentication, please visit
        public void ConfigureAuth(IAppBuilder app)

            // Configure the UserManager
            app.UseUserManagerFactory(new IdentityFactoryOptions<ApplicationUserManager>()
                DataProtectionProvider = app.GetDataProtectionProvider(),
                Provider = new IdentityFactoryProvider<ApplicationUserManager>()
                   OnCreate = ApplicationUserManager.Create

            /// ...
answered by 24.05.2016 / 19:00