Я использую Asp.net Core Authorization, и мне нужно получить имя пользователя в файле startup.cs, но я получил значение NULL.
public void ConfigureServices(IServiceCollection services)
{
// some code here
services.AddHttpContextAccessor();
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddHttpContextAccessor();
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
Audit.Core.Configuration.Setup()
.UseEntityFramework(_ => _
.AuditTypeMapper(t => typeof(AuditLog))
.AuditEntityAction<AuditLog>((ev, entry, entity) =>
{
var svcProvider = services.BuildServiceProvider();
var httpContext = svcProvider.GetService<IHttpContextAccessor>().HttpContext;
entity.AuditData = JsonConvert.SerializeObject(entry);
entity.EntityType = entry.EntityType.Name;
entity.AuditDate = DateTime.Now;
entity.AuditUser = httpContext.User.Identity.Name;
})
.IgnoreMatchedProperties(true));
}