Created
July 5, 2017 18:40
-
-
Save debugthings/a49a3fa00fc6bbb9efe20ed2fb1d80fb to your computer and use it in GitHub Desktop.
Get Authenticated User Id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Web; | |
| using Microsoft.ApplicationInsights.Channel; | |
| public class GetUserInitializer : | |
| Microsoft.ApplicationInsights.Extensibility.ITelemetryInitializer | |
| { | |
| public void Initialize(ITelemetry telemetry) | |
| { | |
| if (telemetry is Microsoft.ApplicationInsights.DataContracts.RequestTelemetry) | |
| { | |
| if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) | |
| { | |
| var telem = telemetry as Microsoft.ApplicationInsights.DataContracts.RequestTelemetry; | |
| var contextIdentity = System.Web.HttpContext.Current.User.Identity.Name; | |
| telem.Context.User.Id = contextIdentity; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment