小编Ted*_*siu的帖子

.Net Core 2.0中的Windows和匿名身份验证

我正在尝试在.Net Core 2.0空Web应用程序中混合使用Windows匿名身份验证.我想避免[Authorize]属性,因为我不想使用Mvc或控制器.

我的设置如下:

  1. 我创建了一个空的.Net Core 2.0 Web应用程序

  2. 我去项目属性 - >调试 - >选中"启用Windows身份验证"并禁用"启用匿名身份验证".现在"windowsAuthentication":true和"anonymousAuthentication":false出现在我的"IIS"下的launchSettings.json中.

  3. 在Startup.cs内部,在ConfigureServices中,我services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);按照https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#windows-authentication-httpsys--iisintegration中的说明添加 了

  4. 我添加了一个简单的内容Console.WriteLine(context.User.Identity.Name);,它可以在app.Run中运行,并且......一切正常!

但是......一旦我在launchSettings.json中将"anonymousAuthentication"设置为true,它就会停止工作,我无法弄清楚我可以做些什么来使Windows身份验证与它一起工作.Context.User.Identity.IsAuthenticated总是假的.正如您所看到的,我的配置非常简单,我需要它保持这种状态.我想在某些动态路由上启用/禁用Windows身份验证,因此使用具有[Authorize]属性的控制器不是一个选项.

我想要实现的是一个简单的应用程序,其中网址"/ authenticated"将回复值,context.User.Identity.Name而网址"/ public"将回复说"这是一个公共页面!".类似于ASP.NET Core中特定路由上的NTLM身份验证,但没有[Authorize]属性和控制器.资源非常稀缺......任何人都知道我可能会缺少什么?谢谢!

.net c# asp.net authentication asp.net-core

13
推荐指数
2
解决办法
6895
查看次数

标签 统计

.net ×1

asp.net ×1

asp.net-core ×1

authentication ×1

c# ×1