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)); } }
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(); }
4.Add the following content To _Layout.cshtml (just before the tag):
##
@StackExchange.Profiling.MiniProfiler.RenderIncludes() </body> </html>
:
<system.webServer> ... <handlers> ... <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" /> ... </handlers> </system.webServer>
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 Example analysis of how ASP.NET uses MiniProfiler to monitor MVC performance in MVC5. For more information, please follow other related articles on the PHP Chinese website!