MVC Mini Profiler Exception on MiniProfiler.Stop()

2019-06-16 11:54发布

问题:

I'm just added Mini Profiler to my MVC3 project with nuget and I've followed the basic steps to get it set up. Starting the profile on Application_BeginRequest() and stopping it on Application_EndRequest()

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

    }

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

MiniProfiler.Stop() is throwing an exception - "Server cannot append header after HTTP headers have been sent."

Has anybody else seen this?

回答1:

Old question but answering anyway.

Problem caused by some component (SignalR in my case) calls HttpResponse.Flush. Solved by excluding SignalR from profiling. Below is a simple version of what we have done.

if (Request.IsLocal && !Request.Path.StartsWith("/signalr"))
{
    MiniProfiler.Start();
}

Hope it helps.



回答2:

This appears to be related to Combres (http://combres.codeplex.com/). If I ignore the requests for my js and css that has been combined and compressed with combres the profiler seems to work better (no exception being thrown)