Я перепробовал слишком много вещей, и ни одна из них не работает, я всегда получаю isAuthenticated = false.
Вот часть моего кода, можете кто-нибудь мне поможет?
Код: Выделить всё
Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddHttpContextAccessor();
...
app.UseAuthentication();
app.UseAuthorization();
Код: Выделить всё
launchingSettings.json:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:2390",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5015",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
}
}
}
Код: Выделить всё
proxy.config.js:
const { env } = require('process');
const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'http://localhost:5015';
const PROXY_CONFIG = [
{
context: [
"/api/MyApi",
],
target,
secure: false,
onProxyRes: proxyRes => {
const key = "www-authenticate";
proxyRes.headers[key] = proxyRes.headers[key] &&
proxyRes.headers[key].split(",");
}
}
]
module.exports = PROXY_CONFIG;
Код: Выделить всё
MyApiController.cs:
public MyApiController(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor;
}
[HttpGet]
public List GetMyApi()
{
// Here I need to get the Windows user and I always get isAuthenticated = false
//...
}
Код: Выделить всё
this.http.get[]>('/api/MyApi', { withCredentials: true })

Дайте мне знать, если вам нужна дополнительная информация, я также был бы признателен, если бы вы указали мне правильное направление, кстати, я новичок в .NET Core.< /п>
Подробнее здесь: https://stackoverflow.com/questions/790 ... net-core-8
Мобильная версия