Mvc-Mini-Profiler: Why are there so many X-MiniProfiler-Ids?

I am using Mvc-Mini-Profiler (what a wonderful product!). Using a normal web browser, everything works fine, but as soon as I use my own http client (basic http 1.1 without cookie support), the number of X-MiniProfiler-Ids in the http header increases. This happens rather quickly and becomes quite a lot in a short period of time (11 KB and above data).

Can a lack of cookies make Mvc-Mini-Profiler work this way or is there something wrong with my implementation?

+5
source share
2 answers

This is by design, I think. Although we could improve the implementation a bit.

X-MiniProfiler-Ids "", . , , , POST .

, (, 20 ) - , .

, - HTTP-, , HTTP-.

, :

// don't run if UserAgent is "my http client"
if(notMyUserAgent)
   MvcMiniProfiler.MiniProfiler.Start();  
+6

- SqlServerStorage UserHasViewed - true. , X-MiniProfiler-Id .

public class MvcMiniProfilerStorage : SqlServerStorage
{
    public MvcMiniProfilerStorage(string connectionString) : base(connectionString)
    {
    }

    /// <summary>
    ///     Stores  to dbo.MiniProfilers under its ;
    ///     stores all child Timings and SqlTimings to their respective tables.
    /// </summary>
    public override void Save(MiniProfiler profiler)
    {
        const string sql =
            @"insert into MiniProfilers
        (Id,
         Name,
         Started,
         MachineName,
         [User],
         Level,
         RootTimingId,
         DurationMilliseconds,
         DurationMillisecondsInSql,
         HasSqlTimings,
         HasDuplicateSqlTimings,
         HasTrivialTimings,
         HasAllTrivialTimings,
         TrivialDurationThresholdMilliseconds,
         HasUserViewed)
select       @Id,
         @Name,
         @Started,
         @MachineName,
         @User,
         @Level,
         @RootTimingId,
         @DurationMilliseconds,
         @DurationMillisecondsInSql,
         @HasSqlTimings,
         @HasDuplicateSqlTimings,
         @HasTrivialTimings,
         @HasAllTrivialTimings,
         @TrivialDurationThresholdMilliseconds,
         @HasUserViewed
where not exists (select 1 from MiniProfilers where Id = @Id)";
        // this syntax works on both mssql and sqlite

        using (DbConnection conn = GetOpenConnection())
        {
            int insertCount = conn.Execute(sql,
                new
                    {
                        profiler.Id,
                        Name = Truncate(profiler.Name, 200),
                        profiler.Started,
                        MachineName = Truncate(profiler.MachineName, 100),
                        User = Truncate(profiler.User, 100),
                        profiler.Level,
                        RootTimingId = profiler.Root.Id,
                        profiler.DurationMilliseconds,
                        profiler.DurationMillisecondsInSql,
                        profiler.HasSqlTimings,
                        profiler.HasDuplicateSqlTimings,
                        profiler.HasTrivialTimings,
                        profiler.HasAllTrivialTimings,
                        profiler.TrivialDurationThresholdMilliseconds,
                        // BUG: Too many X-MiniProfiler-Id headers cause
                        // Firefox to stop all requests
                        //
                        // This hack marks all entries as read so that
                        // they do not end up part of that header.
                        HasUserViewed = true
                    });

            if (insertCount > 0)
            {
                SaveTiming(conn, profiler, profiler.Root);
            }
        }
    }

    private static string Truncate(string s, int maxLength)
    {
        return s != null && s.Length >
                    maxLength ? s.Substring(0, maxLength) : s;
    }
}
+1

All Articles