GetUserManager返回null

时间:2016-05-24 12:25:16

标签: c# .net asp.net-web-api oauth owin

我一直在尝试实施OAuth,但出于某种原因,我一直遇到以下异常:

  

值不能为空。\ r \ nParameter name:context

问题在于Request.GetOwinContext().GetUserManager<ApplicationUserManager>();

我创建了一个包含身份验证的新项目,并不断收到此错误。还试图创建一个空的解决方案,但仍然是同样的问题..

我在启动时确实有以下内容

app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

当我添加这一行时它会起作用:

app.UseCookieAuthentication(new CookieAuthenticationOptions());