【问题标题】:ServiceStack MiniProfiler Ajax Requests LoggingServiceStack MiniProfiler Ajax 请求记录
【发布时间】:2013-04-05 01:08:18
【问题描述】:

所以,在我的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>

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

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

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

【问题讨论】:

    标签: extjs servicestack mvc-mini-profiler


    【解决方案1】:

    我知道这有点旧,但如果有人有兴趣使用 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);
                }
            };
    
        }]);
    }]);
    

    【讨论】:

    • 非常感谢!使用 MiniProfiler 3.0.11,您应该将 fetchResultsExposed 更改为 fetchResults
    【解决方案2】:

    通过 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);
                }
            }
        });
    });
    

    【讨论】:

    • 非常感谢。我会试一试,让你知道它对我有用。
    猜你喜欢
    • 2012-09-19
    • 1970-01-01
    • 2013-07-02
    • 2013-02-08
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多