ASP MVC获取UnitOfWork数据访问层当前用户名的最佳实践?
我无法在UnitOfWork类的UI APP中检索经过身份验证的用户,请提供宝贵的帮助
public override int SaveChanges()
{
var changeSet = ChangeTracker.Entries<IAuditoria>();
if (changeSet != null)
{
string username = "Dafault";
DateTime dateAudit = DateTime.UtcNow;
foreach (var entry in changeSet.Where(c => c.State != EntityState.Unchanged))
{
if (entry.State.Equals(EntityState.Added))
{
entry.Entity.UsuarioCreacion = username;
entry.Entity.FechaCreacion = dateAudit;
}
entry.Entity.GuidAuditoria = Guid.NewGuid().ToString();
entry.Entity.FechaActualizacion = dateAudit;
entry.Entity.UsuarioActualizacion = username;//"HttpContext.Current.User.Identity.Name"
}
}
return base.SaveChanges();
}