首页 > 其他分享 >NetCoreWebApi3.0-------MiniProfiler使用教程

NetCoreWebApi3.0-------MiniProfiler使用教程

时间:2022-09-27 11:46:06浏览次数:74  
标签:function return NetCoreWebApi3.0 ------- configObject ui MiniProfiler var fn

参考博客:ASP.NET Core WebAPI中的分析工具MiniProfiler - LamondLu - 博客园 (cnblogs.com)

 

注意事项:

1.不要盲目copy别人的代码

var html = MiniProfiler.Current.RenderIncludes(HttpContext);

下面我加粗的 这一段代码 请使用这面的语句获取          (html的代码为官网自带的 可以自己去下载 ,也可以试试我的这一段代码)

 

<script async="async" id="mini-profiler" src="/profiler/includes.min.js?v=4.2.22+4563a9e1ab" data-version="4.2.22+4563a9e1ab" data-path="/profiler/" data-current-id="a0e888ed-9ea4-4c14-bfd1-cf3362d5942c" data-ids="a0e888ed-9ea4-4c14-bfd1-cf3362d5942c" data-position="Left" " data-scheme="Light" data-authorized="true" data-max-traces="15" data-toggle-shortcut="Alt+P" data-trivial-milliseconds="2.0" data-ignored-duplicate-execute-types="Open,OpenAsync,Close,CloseAsync"></script>
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>%(DocumentTitle)</title>
    <link rel="stylesheet" type="text/css" href="./swagger-ui.css">
    <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
    <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
    <style>

        html {
            box-sizing: border-box;
            overflow: -moz-scrollbars-vertical;
            overflow-y: scroll;
        }

        *,
        *:before,
        *:after {
            box-sizing: inherit;
        }

        body {
            margin: 0;
            background: #fafafa;
        }
    </style>
    %(HeadContent)
</head>

<body>
    <div id="swagger-ui"></div>

    <!-- Workaround for https://github.com/swagger-api/swagger-editor/issues/1371 -->
    <script>
        if (window.navigator.userAgent.indexOf("Edge") > -1) {
            console.log("Removing native Edge fetch in favor of swagger-ui's polyfill")
            window.fetch = undefined;
        }
    </script>

    <script src="./swagger-ui-bundle.js"></script>
    <script src="./swagger-ui-standalone-preset.js"></script>
    <script>
        /* Source: https://gist.github.com/lamberta/3768814
         * Parse a string function definition and return a function object. Does not use eval.
         * @param {string} str
         * @return {function}
         *
         * Example:
         *  var f = function (x, y) { return x * y; };
         *  var g = parseFunction(f.toString());
         *  g(33, 3); //=> 99
         */
        function parseFunction(str) {
            if (!str) return void (0);

            var fn_body_idx = str.indexOf('{'),
                fn_body = str.substring(fn_body_idx + 1, str.lastIndexOf('}')),
                fn_declare = str.substring(0, fn_body_idx),
                fn_params = fn_declare.substring(fn_declare.indexOf('(') + 1, fn_declare.lastIndexOf(')')),
                args = fn_params.split(',');

            args.push(fn_body);

            function Fn() {
                return Function.apply(this, args);
            }
            Fn.prototype = Function.prototype;

            return new Fn();
        }

        window.onload = function () {
            var configObject = JSON.parse('%(ConfigObject)');
            var oauthConfigObject = JSON.parse('%(OAuthConfigObject)');

            // Workaround for https://github.com/swagger-api/swagger-ui/issues/5945
            configObject.urls.forEach(function (item) {
                if (item.url.startsWith("http") || item.url.startsWith("/")) return;
                item.url = window.location.href.replace("index.html", item.url).split('#')[0];
            });

            // If validatorUrl is not explicitly provided, disable the feature by setting to null
            if (!configObject.hasOwnProperty("validatorUrl"))
                configObject.validatorUrl = null

            // If oauth2RedirectUrl isn't specified, use the built-in default
            if (!configObject.hasOwnProperty("oauth2RedirectUrl"))
                configObject.oauth2RedirectUrl = (new URL("oauth2-redirect.html", window.location.href)).href;

            // Apply mandatory parameters
            configObject.dom_id = "#swagger-ui";
            configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
            configObject.layout = "StandaloneLayout";

            // Parse and add interceptor functions
            var interceptors = JSON.parse('%(Interceptors)');
            if (interceptors.RequestInterceptorFunction)
                configObject.requestInterceptor = parseFunction(interceptors.RequestInterceptorFunction);
            if (interceptors.ResponseInterceptorFunction)
                configObject.responseInterceptor = parseFunction(interceptors.ResponseInterceptorFunction);

            // Begin Swagger UI call region

            const ui = SwaggerUIBundle(configObject);

            ui.initOAuth(oauthConfigObject);

            // End Swagger UI call region

            window.ui = ui
        }
    </script>
</body>
</html>

 

 

2.中间件使用

请按照Swagger在前 使用 否则会产生垃圾日志,也就是 你进入Swagger就会产生耗时

#region Swagger

app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "ZeRunKangCore");
c.RoutePrefix = string.Empty;
c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("ZeRunK_Server.index.html");

});

#endregion Swagger

#region MiniProfiler
//运行时间
app.UseMiniProfiler();
app.UseStaticFiles();

 

 

3.搭配aop使用 效果更佳

标签:function,return,NetCoreWebApi3.0,-------,configObject,ui,MiniProfiler,var,fn
From: https://www.cnblogs.com/jiaozai891/p/16733995.html

相关文章

  • DDL操作表-修改和DML添加,删除,修改
    DDL操作表-修改U(Update):修改修改表名altertable表名renameto新的表名;修改表的字符集altertable表名characterset字符集名称;......
  • Css布局实例 box-sizing使用
    width:33.33%;/*三个框(四框使用25%,两框使用50%,以此类推)*/width:50%;等宽度的两个框。box-Sizing:width+padding+border=元素的实际宽度height+padding......
  • EL-Admin 项目快速上手
    使用该项目前,你需要检查你本地的开发环境,避免出现问题所需环境1、JDK:1.8+2、Redis3.0+3、Maven3.0+4、MYSQL5.5.0+5、Nodev10+TIP前端安装完node后,最好......
  • JavaWeb--HTML & CSS--2022年9月27日
    第一节  HTML--w3school网站可学习1、快速入门A、总结HTML文件以.htm或者.html为扩展名HTML结构标签  ......
  • Vue+Echarts--父组件+子组件(基础)
    基本的思路就是:在父组件获取后端数据,然后传到子组件,子组件创建图表进行展示。1、获取后端数据 2、将数据传给子组件,并将子组件引入到父组件  3、子组件接收数......
  • RT-THREAD nano移植步骤
    1.拷贝所有文件,libcpu,bsp文件夹中只需要拷贝对应M4/M3文件  2.rtthread_startup函数芯片外设初始化,systick初始化。芯片库自带的systick中断入口函数去掉,因为rt-thre......
  • leetcode -- 链表 2
    leetcode链表专题23.合并K个升序链表普通归并排序+python迭代器classSolution:defmergeKLists(self,lists:List[Optional[ListNode]])->Optional[ListNo......
  • 界面组件DevExpress WinForms v22.1 - 全新升级的HTML CSS 模板
    DevExpressWinForms拥有180+组件和UI库,能为WindowsForms平台创建具有影响力的业务解决方案。DevExpressWinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office......
  • SF1606-ASEMI快恢复二极管SF1606
    编辑:llSF1606-ASEMI快恢复二极管SF1606型号:SF1606品牌:ASEMI封装:TO-220AB特性:快恢复二极管正向电流:16A反向耐压:600V恢复时间:35ns引脚数量:3芯片个数:2芯片尺寸:102M......
  • Vue3之script-setup全面解析(转载)
    可能很多同学(包括我)刚上手Vue3.0之后,都会觉得开发过程似乎变得更繁琐了,Vue官方团队当然不会无视群众的呼声,如果你基于脚手架和.vue文件开发,那么可以享受到更高效率......