Missing X-MiniProfiler-Ids from headers in ajax requests

I am using a combination of mvc views and Microsoft WebApi in my application and have installed miniprofiler.

The miniprofiler works great for normal requests for MVC views but it does not refresh when I do ajax requests against webapi methods. However they show up if I refresh the page.

The ajax requests are done using jQuery 1.7.1 and calls ApiController methods in the same application.

The problem seems to be that the json response does not contain the X-MiniProfiler-Ids header.

Am I missing some configuration settings or is this an issue with miniprofiler?

If you could provide a sample for me I would really appreciate it.

Here is the code I am using:

Global.asax

  Shared Sub RegisterGlobalFilters(ByVal filters As GlobalFilterCollection)
        filters.Add(New ProfilingActionFilter())
    End Sub


 Sub Application_Start()
        RegisterGlobalFilters(GlobalFilters.Filters)

        Dim copy = ViewEngines.Engines.ToList()
        ViewEngines.Engines.Clear()

        For Each item In copy
            ViewEngines.Engines.Add(New ProfilingViewEngine(item))
        Next    
    End Sub

Sub Application_BeginRequest()
    StackExchange.Profiling.MiniProfiler.Start()
End Sub

Sub Application_EndRequest()
    StackExchange.Profiling.MiniProfiler.Stop()
End Sub

ApiController:

<ProfilingActionFilter()> _
        Public Function GetChallenges() As IEnumerable(Of ChallengeListItem)
            Using StackExchange.Profiling.MiniProfiler.StepStatic("GetChallenges", StackExchange.Profiling.ProfileLevel.Info)
                Dim vAuthToken As Guid
                Guid.TryParse(HttpContext.Current.Request.Headers.GetValues(AUTHORIZATIONTOKENKEY).FirstOrDefault(), vAuthToken)

                Dim vChallenges As List(Of ChallengeListItem)
                vChallenges = ChallengeData.GetChallenges(vAuthToken)
                Return vChallenges
            End Using
        End Function

Razorview:

 @StackExchange.Profiling.MiniProfiler.RenderIncludes()

javascript request:

this.getChallenges = function (callback) {
            $.ajax({
                type: 'GET',
                url: 'api/Challenges/',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization-Token", userToken);
                },
                success: function (data) {
                    if (callback)
                        callback(data);
                },
                error: function (error) {
                    if (error.status == 401) { 
                        alert('Unauthorized');
                    } else {
                        alert(error.responseText);
                    }
                }
            });
        };

can you debug through it and see that MiniProfiler.Start and MiniProfiler.Stop are being called properly, could there be a filter that is stripping response headers?

I’m having a similar issue. The profiler renders the MVC results but fails to display the API results. In my case, requests to the API are cross-origin, so I’m thinking the header is getting lost after the preflighted request. I’ve tried adding a Access-Control-Expose-Headers header with a value of “X-MiniProfiler-Ids”, but the header is still missing on my API response.