Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule.AddTargetHashForResponseHeader C# (CSharp) Method

AddTargetHashForResponseHeader() public method

Adds target response header response object.
public AddTargetHashForResponseHeader ( HttpContext context ) : void
context System.Web.HttpContext
return void
        public void AddTargetHashForResponseHeader(HttpContext context)
        {
            if (this.telemetryClient == null)
            {
                throw new InvalidOperationException();
            }

            var requestTelemetry = context.GetRequestTelemetry();

            if (string.IsNullOrEmpty(requestTelemetry.Context.InstrumentationKey))
            {
                // Instrumentation key is probably empty, because the context has not yet had a chance to associate the requestTelemetry to the telemetry client yet.
                // and get they instrumentation key from all possible sources in the process. Let's do that now.
                this.telemetryClient.Initialize(requestTelemetry);
            }

            if (!string.IsNullOrEmpty(requestTelemetry.Context.InstrumentationKey)
                && context.Response.Headers[RequestResponseHeaders.TargetInstrumentationKeyHeader] == null)
            {
                context.Response.Headers[RequestResponseHeaders.TargetInstrumentationKeyHeader] = InstrumentationKeyHashLookupHelper.GetInstrumentationKeyHash(requestTelemetry.Context.InstrumentationKey);
            }
        }