.NETMVC5使用MiniProfiler

一、工具-NuGet包管理器-管理解决方案的NuGet程序包

二、Global.asax.cs

protected void Application_Start()
{
    InitProfilerSettings();
}

protected void Application_BeginRequest()
{

    MiniProfiler profiler = null;
    profiler = MiniProfiler.StartNew();
}

protected void Application_EndRequest()
{
    MiniProfiler.Current?.Stop();
}

private void InitProfilerSettings()
{
  
    MiniProfilerOptions MiniProfilerOptions = new MiniProfilerOptions
    {
        Storage = new MultiStorageProvider(new MemoryCacheStorage(new TimeSpan(1, 0, 0))),
 
        PopupRenderPosition = RenderPosition.Left,  // defaults to left
        PopupMaxTracesToShow = 10,                   // defaults to 15

        ResultsAuthorize = request =>
        {
            if ("/home/resultsauthorization".Equals(request.Url.LocalPath, StringComparison.OrdinalIgnoreCase))
            {
                return (request.Url.Query).IndexOf("isauthorized", StringComparison.OrdinalIgnoreCase) >= 0;
            }

            return !DisableProfilingResults;
        },

        ResultsListAuthorize = request =>
        {
          return true;
        },

        StackMaxLength = 256, 
        TrackConnectionOpenClose = true
    }

    .ExcludeType("SessionFactory") 
    .ExcludeAssembly("NHibernate") 
    .ExcludeMethod("Flush");

    MiniProfilerOptions.IgnorePath("/__browserLink");//忽略browserLink
    MiniProfilerOptions.ShowControls = true; // 提示条上显示“m”和“c”
    MiniProfiler.Configure(MiniProfilerOptions);

    MiniProfilerEF6.Initialize();
}

三、页面中

@using StackExchange.Profiling
<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>

@MiniProfiler.Current.RenderIncludes(position: RenderPosition.Right, showTrivial: false, showTimeWithChildren: true)
</body>
</html>

四、webconfig.xml

<system.webServer>
    <modules runAllManagedModulesForAllRequests="false" />
    <handlers>
      <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
    </handlers>
</system.webServer>

备注:

1、监控不到Z.EntityFramework.Plus.EF6生成的SQL,也许有其他方法实现,你可以深入探索。

2、使用方法见官网https://miniprofiler.com/dotnet

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在ASP.NET MVC中,你可以使用多种方法进行数据缓存。以下是几种常见的数据缓存技术: 1. Output Caching(输出缓存):这是一种将整个页面或页面片段缓存到服务器内存中的技术。当下次请求相同的页面时,服务器将直接返回缓存的内容,而不执行相应的控制器和视图逻辑。你可以使用OutputCache属性来设置缓存的持续时间、缓存依赖项等。 2. Memory Caching(内存缓存):这是一种将数据存储在服务器内存中的技术。你可以使用MemoryCache类来实现内存缓存。这对于需要频繁读取的数据非常有用,比如配置数据或静态数据。你可以设置缓存项的过期时间、优先级等。 3. Distributed Caching(分布式缓存):当你的应用程序运行在多个服务器上时,你可能需要使用分布式缓存来共享缓存数据。一些流行的分布式缓存解决方案包括Redis、Memcached和Microsoft Azure Redis Cache等。 4. Session State Caching(会话状态缓存):ASP.NET MVC提供了会话状态机制,允许你将数据存储在服务器上供整个会话使用。你可以使用Session对象来读取和写入会话状态数据。默认情况下,会话状态被存储在服务器的内存中,但你也可以配置它使用分布式缓存。 这些技术可以单独或结合使用,具体取决于你的应用程序需求和性能要求。记得根据具体场景选择合适的缓存技术,并避免过度缓存或无效的缓存。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值