[英]Secure File Download Using Blazor Webassembly and ASP.NET Core
[英]Using Windows Authentication in Blazor WebAssembly with .NET Core
我一直在研究和测试一些看起来很简单但对我不起作用的东西。
我只想通过 Windows 身份验证获取当前用户主体,但似乎身份验证方案没有正确连接?
这是当我将 Authorize 属性添加到刚刚获取 User.Identity.Name 值的 controller 时:
[Authorize]
[HttpGet("getUser")]
public string? GetUser()
{
return User?.Identity?.Name;
}
这只是VS 2022中的blazor wasm模板示例,所以在程序中:
builder.Services.AddAuthentication(IISDefaults.Negotiate);
当我删除授权并检查用户主体时,它有一个为空的声明。
在启动设置中启用 Windows Auth:
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:31120",
"sslPort": 44346
}
},
"profiles": {
"BlazorApp2.Server": {
"commandName": "Project",
"windowsAuthentication": true,
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7139;http://localhost:5139",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
显然,我在做一些非常愚蠢的事情,但是有人可以启发我吗?
谢谢。
好的,看来我通过拉入Microsoft.AspNetCore.Authentication.Negotiate package 让它工作了。
并切换到协商身份验证方案。 我以为我已经尝试过了,但一定有一些不太正确的地方:
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
我还注意到 controller 操作需要Authorize属性,否则用户原则仍然为空?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.