作为记录输入/更新数据的一部分,我在所有实体中添加了4个常用字段(创建者,创建日期,修改者,修改日期)。为此,我使用多个论坛中建议的影子属性功能,包括https://dotnetcore.gaprogman.com/2017/01/26/entity-framework-core-shadow-properties/
我的问题是如何获取有关经过身份验证的用户的信息?。如果它是一个控制器,我可以访问ApplicationUserManager,但在这种情况下,阴影属性在
AppDbContext:IdentityDbContext class。
这是一个asp.net核心2 Web API项目。
任何建议都非常感谢。感谢
答案 0 :(得分:4)
您可以使用 INFO: Parse coverage report
(DerivedData/iOS_Template/Build/ProfileData/DDA1A82C-EB41-4E45-8DCF-428D3E879067/Coverage.profdata)
ERROR: Can't parse coverage report file
(DerivedData/iOS_Template/Build/ProfileData/DDA1A82C-EB41-4E45-8DCF-428D3E879067/Coverage.profdata).
No coverage information will be saved.
java.lang.IllegalStateException: Can not parse line: HƢ�F
_T0SS17iOS_TemplateTestsE11isValidatedSbAA10ValidationO10validation_tF�.�������k(_T09Alamofire12TaskDelegateC10urlSessionySo10URLSessionC_So0fB0C4taskySo11InputStreamCSgc011needNewBodyI0t3��6K�2@_T09Alamofire14SessionManagerC5retrySbAA7RequestC383��J��Z8_T09Alamofire7AFErrorO31ResponseValidationFailureReasonO22acceptableContentTypesSaySSGSgf6(��W��N
[...similar set of unknown characters...]
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at java.util.Optional.ifPresent(Optional.java:159)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.B.A(Unknown Source)
at com.sonar.swift.plugin.D.A(Unknown Source)
at com.sonar.swift.plugin.D.execute(Unknown Source)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
.....
获取当前用户的姓名。您可以使用HttpContext.User.Identity.Name
访问HttpContext
。此接口应已在服务集合中注册。否则,您可以注册:
IHttpContextAccessor
然后,您可以使用public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
// ...
}
:
DbContext