HttpContext.GetOwinContext().GetUserManager() return null

后端 未结 2 638
旧时难觅i
旧时难觅i 2021-02-05 10:24

I\'ve used ASP.NET Identity 2 for creating role but the result of HttpContext.GetOwinContext().GetUserManager() was null.

Then I could

2条回答
  •  忘掉有多难
    2021-02-05 10:39

    Most likely you have missed giving OwinContext the way to create ApplicationUserManager.
    For that you'll need to have these in your public void Configuration(IAppBuilder app)

    app.CreatePerOwinContext(ApplicationUserManager.Create);
    app.CreatePerOwinContext(AppRoleManager.Create);
    

    This will register delegates that create UserManager and RoleManager with OwinContext and only after that you can call these back in your controllers.

提交回复
热议问题