【发布时间】:2021-09-01 20:15:37
【问题描述】:
我的问题类似于Postman Windows Authentication (NTLM) not working,但目前还没有答案。
我使用了 .NetCore rest api (netcoreapp3.1)。
-
在launchsettings.json中
{ "iisSettings": { "windowsAuthentication": true, "anonymousAuthentication": false, .. } -
Startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(IISDefaults.AuthenticationScheme); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //... app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); //....useEndpoints middleware is being called afterwards } -
EmployeeController.cs
[Route("IISDetails")] [HttpGet] public IActionResult IISDetails() { var name = User.Identity.Name; return new ContentResult() { Content = $@"IIS authorized. AD: {name}" }; }
我没有使用 [Authorize] 标记,因此至少我可以看到这是否有效,但名称始终为空。
邮递员我在授权选项卡中设置用户名。附上图片供参考。
如果我将 Authorize 属性添加到我的 IISDetails 函数中,它会给我
System.InvalidOperationException: 没有指定 authenticationScheme,也没有找到 DefaultChallengeScheme。
【问题讨论】:
标签: api authentication .net-core windows-authentication authenticationchallenge