4

I have an ASP.NET MVC5 single page web application that uses angularjs to make ajax calls to an ASP.NET Web API 2 application, all of them being visible in the Chrome developer tools Network tab. However, Glimpse does not capture the ajax calls, neither in HUD, nor in the Ajax tab. I've added application/json to the glimpse content types in web.config. I also added the X-Requested-With header to my angularjs ajax calls:

$httpProvider.defaults.headers.common = { 'X-Requested-With': 'XMLHttpRequest' };

Yet the HUD keeps showing 0 ajax requests, and there is nothing in the Ajax tab. Is there anything else I should do? How can I troubleshoot this?

2 Answers2

5

I know this is an old question but the following in web config worked for me:

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
    <runtimePolicies>
      <statusCodes>
        <add statusCode="201" />
        <add statusCode="202" />
        <add statusCode="203" />
        <add statusCode="204" />
        <add statusCode="404" />
      </statusCodes>
    </runtimePolicies>
</glimpse>

Also Glimpse identifies AJAX calls by the X-Requested-With: XMLHttpRequest header. AngularJS $http calls do not include this header by default, so they do not show up in the AJAX panel in Glimpse. We can change the defaults on $httpProvider to always add this header…

app.config(['$httpProvider', function ($httpProvider) {
    $httpProvider.defaults.headers.common = { 'X-Requested-With': 'XMLHttpRequest' };
}]);

Source: http://anthonychu.ca/post/getting-angularjs-http-and-web-api-to-work-with-glimpse (note incorrect case in the example at the link, use the above instead)

Korayem
  • 12,108
  • 5
  • 69
  • 56
brahnp
  • 2,276
  • 1
  • 17
  • 22
  • In AngularJS 1.1.x+ you'll need to implement an intercept to set the common headers http://stackoverflow.com/questions/14183025/setting-application-wide-http-headers-in-angularjs. I've done this and I can see the header, though I only see the dynamic requests for html views and no JSON requests in the list of AJAX calls in Glimpse. Any suggestions? – Josh Russo Dec 28 '16 at 02:07
2

I had a similar issue trying to use glimpse with pace.js. Removing it allowed the ajax requests to propagate correctly in glimpse.

You could try disabling other javascript libraries that handle ajax events and see if you have any better luck. My end solution was to disable pace.js for administrative users (the only ones who would see the glimpse UI anyway).

Paul
  • 21
  • 1