问题
Is there an MVC6 compatible version of WebTelemetryInitializerBase
that would work with ASP.NET Core (on the full .NET Framework)?
See my question here where I asked how to get HttpContext
in my temeletry initializers. Unfortunately I didn't specify that I was using MVC 6 and thus no System.Web.HttpContext
.
回答1:
Yes, there is a version of this for aspnetcore. Check out the Microsoft Application Insights for ASP.NET Core applications repo.
There is an implementation of getting the WebUser found in /src/Microsoft.ApplicationInsights.AspNetCore/TelemetryInitializers/WebUserTelemetryInitializer.cs which you can use as a guide.
The TelemetryInitializerBase class is the one that consumes the IHttpContextAccessor which is used to get the HttpContext.
From there you can get the Microsoft.AspNetCore.Http.HttpContext.User which is they type of System.Security.Claims.ClaimsPrincipal
来源:https://stackoverflow.com/questions/38418682/webtelemetryinitializerbase-in-asp-net-core-mvc6