• .NET Core报错: No authenticationScheme was specified
  • 发布于 2个月前
  • 103 热度
    1 评论

我的.NET Core项目启动时,系统报错:InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action<AuthenticationOptions> configureOptions).

这是啥意思?新手.NET,表示找不到错误原因,是缺少什么吗?

用户评论
  • 繁华的年代
  • 你这个应该是系统中没有添加身份认证方式,但是在代码中又启用了身份验证的属性,可以尝试在Program.cs文件中加入如下这段代码:

    builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme,
            options => builder.Configuration.Bind("JwtSettings", options))
        .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
            options => builder.Configuration.Bind("CookieSettings", options));

  • 2024/4/15 21:56:00 [ 0 ] [ 0 ] 回复