【问题标题】:Sentry doesn't show HttpContext User info in ASP.NET Core applicationSentry 在 ASP.NET Core 应用程序中不显示 HttpContext 用户信息
【发布时间】:2019-05-31 12:53:35
【问题描述】:

我只使用了网页中的基本 Sentry 配置。

  "Sentry": {
    "Dsn": "",
    "IncludeRequestPayload": true,
    "SendDefaultPii": true,
    "MinimumBreadcrumbLevel": "Debug",
    "MinimumEventLevel": "Warning",
    "AttachStackTrace": true,
    "Debug": true,
    "DiagnosticsLevel": "Error"
  }

根据我收集的信息,我应该看到 Setry 使用其从 HttpContext.User 的中间件获取的用户信息。

但在网页上我只看到 Ip ::1

我应该配置其他东西吗?我似乎找不到任何额外的配置。

编辑

我使用的是 Sentry 1.2.0 版。我的 HttpContext。

使用用户信息确定用户设置。

对于身份验证,我使用的是 Jwt 令牌

services.AddAuthentication(options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; })

问候

【问题讨论】:

  • 好吧,你很可能没有用户并且 ::1 它不是你的本地 ip
  • 您使用的是什么版本的 Sentry.AspNetCore?
  • @SilentTremor 用户已设置。我已经用更多信息编辑了我的答案

标签: asp.net-core sentry


【解决方案1】:

latest release (version 1.2.0, from 8 days ago) 包含一个错误修复,即用户在由应用程序手动设置时未正确报告。

在任何情况下,应该通过阅读ClaimsPrincipal 自动报告请求中存在的用户。这可以通过将您自己的IUserFactory 实现添加到容器中来更改,这允许您通过检查HttpContext 创建一个User 对象。

如果您使用的是 1.2.0 版本但仍有问题,请在 Sentry .NET SDK 的 GitHub 存储库中提出问题:

https://github.com/getsentry/sentry-dotnet/issues/new

【讨论】:

  • 我使用的是 1.2.0 版。我会提出一个问题。谢谢!
【解决方案2】:

我不记得我在我工作的一个项目中使用的版本,我不记得确切地从哪里检测到“用户”,但如果我记得正确的话是 ControllerBase.User

不管怎样,看你得到了什么授权机制,也许你需要把HttpContext.User注入ControllerBase.User(typeof ClaimsPrincipal)

在你的 serviceCollection(我猜是启动)上这样做:

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IPrincipal>(provider => provider.GetService<IHttpContextAccessor>().HttpContext?.User);

【讨论】:

  • 我检查了 ControllerBase.User 的值,它与 HttpContext.User 中的值相同。我仍然尝试了您的代码示例,但没有任何帮助。
猜你喜欢
  • 2019-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多