ServiceStack MiniProfiler Ajax请求记录

时间:2013-04-05 01:08:18

标签: extjs servicestack mvc-mini-profiler

所以,在我的Index.cshtml页面中,当我最初加载页面时,我有:

@inherits ViewPage
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="ext-all-debug.js"></script>
        <script type="text/javascript" src="app.js"></script>
        <script type="text/javascript" src="app.ext.js"></script>
        <script type="text/javascript" src="dump.js"></script>
        @ServiceStack.MiniProfiler.Profiler.RenderIncludes().AsRaw() 
    </head>
    <body> 
    </body>
</html>

enter image description here

一切都很好,我可以看到它的分析索引,一堆ExtJS,以及服务器端的第一个ajax调用我的ServiceStack(在/ api / session中)。

现在,在我的ExtJS表单中,当我点击它时,我有一个Customers选项卡向/api/customers发送ajax请求,当我点击它时,我有一个标签调用/api/orders

但是,当我开始点击“客户”选项卡时,Miniprofiler不再将任何后续的ajax请求添加到列表中?我以为Miniprofiler可以记录ajax请求没什么特别需要做的吗?为什么不为我记录后续的ajax请求?我错过了什么?

2 个答案:

答案 0 :(得分:6)

我知道这有点旧,但如果有人对此感兴趣,使用miniprofiler和angularjs的实现如下:

app.config(['$httpProvider', function ($httpProvider) {

    $httpProvider.interceptors.push(["$q", function ($q) {

        return {
            'response': function (response) {

                if (typeof (MiniProfiler) != 'undefined' && response.config.url.indexOf(".html") < 0) {
                    var stringIds = response.headers('X-MiniProfiler-Ids');
                    if (stringIds) {
                        MiniProfiler.fetchResultsExposed(angular.fromJson(stringIds));
                    }
                }

                return response || $q.when(response);
            }
        };

    }]);
}]);

答案 1 :(得分:5)

Nuget提供的当前版本不支持拦截ExtJS ajax调用。 该功能似乎有一个pull request,但它还没有。

这是我必须做的事情来解决这个问题:

Ext.require('Ext.Ajax');
Ext.onReady(function () {
    Ext.Ajax.on('requestcomplete', function (e, xhr, settings) {
        if (typeof (MiniProfiler) != 'undefined') {
            var stringIds = xhr.getResponseHeader('X-MiniProfiler-Ids');
            if (stringIds) {
                var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
                MiniProfiler.fetchResultsExposed(ids);
            }
        }
    });
});