我正在尝试使用 mcr.microsoft.com/dotnet/core/在 Docker linux 容器 中的 Visual Studio 2019 中使用 .NET CORE 3.0 应用程序解决方案启用 Windows 身份验证 aspnet:3.0 图像。我可以使用 gMSA 帐户在 IIS Windows 容器中进行此设置,不会出现任何问题,但是当涉及到 linux 容器和 aspnet:3.0 时,如果我使用 [Authorize] 属性且 User.Identity.Name 未使用,我将无法收到凭据提示人口。如果这可能的话,我从互联网上得到了混合信号,但到目前为止还无法找到简洁的答案。只是尝试注册服务 JWT/IISDefaults/HttpSysDefaults/Oauth、app.UseAuthentication、修改启动设置和应用程序 settings.json 等不同的操作,但没有成功。任何帮助将不胜感激。
最佳答案
我在一个项目中遇到了这个问题,我设法在 ASP.NET 中获得凭据提示,如下所示: 在您需要授权访问的 Controller 上方,放置 Authorize 属性,如下所示:
[Authorize(Policy = "SomeExampleGroup")]
[Route("/some-example")]
public class SomeExampleController : Controller {...}
在Startup.cs的ConfigureServices方法中:
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
services.AddAuthentication(o => o.DefaultAuthenticateScheme = NegotiateDefaults.AuthenticationScheme);
services.AddAuthorization(options =>
{
options.AddPolicy("SomeExampleGroup",
policy => policy.RequireAssertion(/*some assertion here for example*/));
});
并在配置方法中确保放置
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
按此顺序。无论如何,我设法在像这样的 Linux 容器中获得 Docker 上的凭据提示,但凭据仍然不起作用,所以我希望这会有所帮助。
关于linux - .NET CORE 3.0 在 Linux 上的 docker 中使用 Windows 身份验证可以工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58528876/