Подтвердить что ты не робот

MiniProfiler не отображается на asp.net MVC

Я добавил это в свой файл Global.asax.cs:

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

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

Я добавил

@MiniProfiler.RenderIncludes()

чуть ниже тега </body> в _Layout.cshtml.

В моем контроллере я использую:

 public class HomeController : Controller
    {
        public ActionResult Index()
        {    
            var profiler = MiniProfiler.Current; // it ok if this is null
            using (profiler.Step("Set page title"))
            {
                ViewBag.Title = "Home Page";
            }
            using (profiler.Step("Doing complex stuff"))
            {
                using (profiler.Step("Step A"))
                { // something more interesting here
                    Thread.Sleep(100);
                }
                using (profiler.Step("Step B"))
                { // and here
                    Thread.Sleep(250);
                }
            }

            return View("~/Views/Home/Index.cshtml");
        }
    }

Но на моей странице ничего не отображается, нет окна профиля.

При просмотре исходного кода я вижу только это:

<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-version="xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-path="/mini-profiler-resources/" data-current-id="6d24704e-3003-44f8-9965-437c6275d639" data-ids="8ec2c718-4375-4d3f-9b69-4092e534143e,6d24704e-3003-44f8-9965-437c6275d639" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>
4b9b3361

Ответ 1

В вашем web.config добавьте следующее:

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

Если вы хотите получить профилирование MVC Action (не связанное с вашей проблемой), добавьте эту строку в Application_Start в Global.asax.cs:

GlobalFilters.Filters.Add(new StackExchange.Profiling.MVCHelpers.ProfilingActionFilter());

Ответ 2

Если кто-нибудь попробовал решение Alden и все еще не работает для вас, попробуйте установить discardResults на false, как предложено willgrosett

   // Global.asax.cs file
   protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
        }
    }

    protected void Application_EndRequest(object sender, EventArgs e)
    {
        MiniProfiler.Stop(discardResults: false);
    }

Ответ 3

В MiniProfiler последняя версия: 4.0.165. Убедитесь, что вы добавили код в Application_Start()

protected void Application_Start()
{
    ...
    MiniProfiler.Configure(new MiniProfilerOptions());//default setting
    MiniProfilerEF6.Initialize();
}

Док находится здесь: https://miniprofiler.com/dotnet/AspDotNet

И в последней версии вам не нужно добавлять

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

в Web.config больше.