.net core 在身份验证之前,正在对.net core 2应用程序中的日志进行加密
我有一个dotnet core 2 web应用程序,我已经用Enricher配置了SeriLog,这样我就可以在每次请求时使用“配置”方法记录用户的电子邮件:.net core 在身份验证之前,正在对.net core 2应用程序中的日志进行加密,.net-core,serilog,.net Core,Serilog,我有一个dotnet core 2 web应用程序,我已经用Enricher配置了SeriLog,这样我就可以在每次请求时使用“配置”方法记录用户的电子邮件: // Log user app.Use(async (context, next) => { using (Serilog.Context.LogContext.PushProperty("UserId", context.User.Claims.Whe
// Log user
app.Use(async (context, next) =>
{
using (Serilog.Context.LogContext.PushProperty("UserId", context.User.Claims.Where(a => a.Type == ClaimTypes.Email).FirstOrDefault().Value))
{
await next.Invoke();
}
});
app.UseMvc();
不幸的是,这种情况发生在身份验证之前,因此电子邮件从未设置
如何在身份验证后实现这一点?在“ConfigureServices”方法中以标准方式配置身份验证,如下所示:
services.AddAuthentication(...
我有一个类似的问题,需要在自定义中间件组件中使用身份验证数据。 简单地说
app.UseAuthentication();
在自定义使用中间件之前,使用相关的用户数据填充上下文
希望有帮助。我也遇到过类似的问题,需要在自定义中间件组件中使用身份验证数据。 简单地说
app.UseAuthentication();
在自定义使用中间件之前,使用相关的用户数据填充上下文
希望能有帮助