1

我正在将 ASP.NET Identity 与 ASP.NET 核心一起使用,并且我有:

services.AddIdentity<User, Role>();

当我登录时,这工作正常。但后来我尝试了这个设置:

services
  .AddIdentity<User, Role>(x => {
    x.Cookies = new IdentityCookieOptions {             
      ApplicationCookie = new CookieAuthenticationOptions {
        AccessDeniedPath = new PathString("/signin"),
        AuthenticationScheme = "cookies",
        AutomaticAuthenticate = true,
        AutomaticChallenge = true,
        CookieName = "_ath",
        LoginPath = new PathString("/signin"),
        LogoutPath = new PathString("/signout")
      }
    };
    })
    .AddEntityFrameworkStores<Context, Int32>()
    .AddDefaultTokenProviders();          

有了这个我得到以下错误:

No authentication handler is configured to handle the scheme: 
Microsoft.AspNet.Identity.Application    

请注意,我有AuthenticationScheme = "cookies"和。AutomaticAuthenticate = trueAutomaticChallenge = true

我在 Starttup / Configure 方法中也有以下内容:

  applicationBuilder
    .UseIdentity()
    .UseMvc(routes => { routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); })

所以我想我正在使用默认顺序......

有谁知道我错过了什么?

4

2 回答 2

0

不要直接设置 authenticationScheme,或者如果你这样做了,你需要确保你也更新了 IdentityOptions 中的相应选项以完全匹配。

错误消息意味着身份可能仍配置为在某处使用默认值“Microsoft.AspNet.Identity.Application”,并且您将 cookie 中间件更改为不匹配的不同方案。

于 2016-04-04T22:57:40.947 回答
0

我遇到了完全相同的错误并设法通过添加默认令牌提供程序来修复它,如下所示:

services.AddIdentity<User, IdentityRole>()
            .AddDefaultTokenProviders();
于 2016-04-01T15:15:20.167 回答