c# - Asp.Net Core 未找到 DefaultChallengeScheme
问题描述
AuthorizationHandler
我在我的 Asp.Net Core API 项目中有一个自定义,它根据在Headers
.
工作正常,Handler
因为它在运行时调用但是我收到以下错误
InvalidOperationException:未指定 authenticationScheme,也未找到 DefaultChallengeScheme。
我已将我的设置注册Startup.cs
如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddSingleton<IAuthorizationHandler, TokenAuthorizationHandler>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseAuthentication();
app.UseMvc();
}
有什么建议么?
解决方案
该项目的默认属性是启用匿名身份验证和禁用 Windows 身份验证。
如果您想选择IIS 默认身份验证作为您的 authenticationScheme ,您需要修改项目的属性以启用 Windows 身份验证并禁用匿名身份验证:
右键单击解决方案资源管理器中的项目并选择Properties。
选择调试选项卡。
清除Enable Anonymous Authentication的复选框。
选中启用 Windows 身份验证复选框。
保存并关闭属性页。
或者您可以添加其他 authenticationSchemes(基于 cookie 的身份验证、JWT 不记名身份验证等),有关详细信息,请参阅使用 ASP.NET Core 中的特定方案进行授权。
推荐阅读
- angular - 离子电容闪屏不工作
- angular - 如何在我的 Angular 测验应用程序中修复多选题的评分?
- spring-cloud - 登录到 Spring Cloud Api Gateway 后面的 Keycloak
- python - 尝试规范化和更新权重时收到运行时警告
- javascript - 使用 Gatsby LInk 导航时,来自 Ebay 的 Ins 小部件不显示,但使用常规标签时会显示
- visual-studio-code - Dafny 在 MacOS 10.14.6 上的 Visual Studio Code 中失败:有人知道单声道在哪里吗?
- php - 将数据库及其表复制到新数据库及其新表,仅限 PHP,无 PhpMyAdmin
- reactjs - 将 react-table 与 react-modal 一起使用
- vba - 使用 vba 添加新记录时跳过空白字段
- python - 在 main 中从其他函数定义的打印变量