Skip to content

Instantly share code, notes, and snippets.

@debugthings
Created July 5, 2017 18:40
Show Gist options
  • Select an option

  • Save debugthings/a49a3fa00fc6bbb9efe20ed2fb1d80fb to your computer and use it in GitHub Desktop.

Select an option

Save debugthings/a49a3fa00fc6bbb9efe20ed2fb1d80fb to your computer and use it in GitHub Desktop.
Get Authenticated User Id
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