How to use MVC5's MiniProfiler to monitor the performance of MVC in ASP.NET

巴扎黑
Release: 2017-08-06 10:48:04
Original
1222 people have browsed it

This article mainly introduces in detail how ASP.NET MVC5 uses MiniProfiler to monitor MVC performance. It has certain reference value. Interested friends can refer to

MiniProfiler, a simple and effective tool. Mini profiler can effectively monitor pages in real time. Monitor other pages accessed through direct reference, Ajax, and Iframe. The monitoring content includes database content and can display the SQL of database access.

1. Installation

First create a new asp.net mvc project

Right-click the project and manage NuGet packages. Install MiniProfiler.Mvc4 and MiniProfiler

ps:MiniProfiler.MVC4 NuGet package (this MVC4 package supports MVC5)

Or you can also open the package management control Enter the command to install

Install-Package MiniProfiler -Version 3.2.0.157

##Install-Package MiniProfiler.Mvc4 -Version 3.0.11

2. Add the following content to Application_Start()Global.asax


protected void Application_Start()
{
 ...
 GlobalFilters.Filters.Add(new ProfilingActionFilter());

 var copy = ViewEngines.Engines.ToList();
 ViewEngines.Engines.Clear();
 foreach (var item in copy)
 {
  ViewEngines.Engines.Add(new ProfilingViewEngine(item));
 }
}
Copy after login

3. Add the following content to "Application_BeginRequest()" and "Application_EndRequest()" also in Global.asax


protected void Application_BeginRequest()
{
 if (Request.IsLocal)
 {
  MiniProfiler.Start();
 }
}

protected void Application_EndRequest()
{
 MiniProfiler.Stop();
}
Copy after login

4.Add the following content To _Layout.cshtml (just before the tag):

##

 @StackExchange.Profiling.MiniProfiler.RenderIncludes()
</body>
</html>
Copy after login

5. Add the following to Section of Web.config

:

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

If you use Entity Framework in your project, then you can install the MiniProfiler.EF6 package in Application_Start() The following content is added at the end of Global.asax: MiniProfilerEF6.Initialize();

That’s it for a simple monitoring of MVC performance. In fact, it has many functions, such as being able to detect and Highlight areas where the same query is executed. This way you can quickly find possible batches of queries.

You can also record all ajax calls, view the analysis information of the last 100 analysis requests, etc.

Result display:

The above is the detailed content of How to use MVC5's MiniProfiler to monitor the performance of MVC in ASP.NET. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!