Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebTelemetryInitializerBase in ASP.NET Core / MVC6

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.

like image 752
Dave New Avatar asked Jul 17 '16 06:07

Dave New


Video Answer


1 Answers

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

like image 155
James Davis - MSFT Avatar answered Nov 15 '22 11:11

James Davis - MSFT