コード例 #1
0
        /// <summary>
        /// Handles rendering a previous <c>MiniProfiler</c> session, identified by its <c>"?id=GUID"</c> on the query.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>a string containing the rendered content</returns>
        private static string Results(HttpContext context)
        {
            // when we're rendering as a button/popup in the corner, we'll pass ?popup=1
            // if it's absent, we're rendering results as a full page for sharing
            var isPopup = context.Request["popup"].HasValue();

            // this guid is the MiniProfiler.Id property
            // if this guid is not supplied, the last set of results needs to be
            // displayed. The home page doesn't have profiling otherwise.
            Guid id;

            try
            {
                id = new Guid(context.Request["id"]);
            }
            catch (Exception)
            {
                id = MiniProfiler.Settings.Storage.List(1).FirstOrDefault();
            }

            if (id == default(Guid))
            {
                return(isPopup ? NotFound(context) : NotFound(context, "text/plain", "No Guid id specified on the query string"));
            }

            MiniProfiler.Settings.EnsureStorageStrategy();
            var profiler = MiniProfiler.Settings.Storage.Load(id);

            var    provider = WebRequestProfilerProvider.Settings.UserProvider;
            string user     = null;

            if (provider != null)
            {
                user = provider.GetUser(context.Request);
            }

            MiniProfiler.Settings.Storage.SetViewed(user, id);

            if (profiler == null)
            {
                return(isPopup ? NotFound(context) : NotFound(context, "text/plain", "No MiniProfiler results found with Id=" + id.ToString()));
            }

            bool needsSave = false;

            if (profiler.ClientTimings == null)
            {
                profiler.ClientTimings = ClientTimings.FromRequest(context.Request);
                if (profiler.ClientTimings != null)
                {
                    needsSave = true;
                }
            }

            if (profiler.HasUserViewed == false)
            {
                profiler.HasUserViewed = true;
                needsSave = true;
            }

            if (needsSave)
            {
                MiniProfiler.Settings.Storage.Save(profiler);
            }

            var authorize = MiniProfiler.Settings.Results_Authorize;

            if (authorize != null && !authorize(context.Request))
            {
                context.Response.ContentType = "application/json";
                return("hidden".ToJson());
            }

            return(isPopup ? ResultsJson(context, profiler) : ResultsFullPage(context, profiler));
        }
コード例 #2
0
        /// <summary>
        /// Handles rendering a previous MiniProfiler session, identified by its "?id=GUID" on the query.
        /// </summary>
        private static string Results(HttpContext context)
        {
            // when we're rendering as a button/popup in the corner, we'll pass ?popup=1
            // if it's absent, we're rendering results as a full page for sharing
            var isPopup = !string.IsNullOrWhiteSpace(context.Request["popup"]);

            // this guid is the MiniProfiler.Id property
            Guid id;

            if (!Guid.TryParse(context.Request["id"], out id))
            {
                return(isPopup ? NotFound(context) : NotFound(context, "text/plain", "No Guid id specified on the query string"));
            }

            MiniProfiler.Settings.EnsureStorageStrategy();
            var profiler = MiniProfiler.Settings.Storage.Load(id);

            var    provider = WebRequestProfilerProvider.Settings.UserProvider;
            string user     = null;

            if (provider != null)
            {
                user = provider.GetUser(context.Request);
            }

            MiniProfiler.Settings.Storage.SetViewed(user, id);

            if (profiler == null)
            {
                return(isPopup ? NotFound(context) : NotFound(context, "text/plain", "No MiniProfiler results found with Id=" + id.ToString()));
            }

            bool needsSave = false;

            if (profiler.ClientTimings == null)
            {
                profiler.ClientTimings = ClientTimings.FromRequest(context.Request);
                if (profiler.ClientTimings != null)
                {
                    needsSave = true;
                }
            }

            if (profiler.HasUserViewed == false)
            {
                profiler.HasUserViewed = true;
                needsSave = true;
            }

            if (needsSave)
            {
                MiniProfiler.Settings.Storage.Save(profiler);
            }


            var authorize = MiniProfiler.Settings.Results_Authorize;


            if (authorize != null && !authorize(context.Request))
            {
                context.Response.ContentType = "application/json";
                return("hidden".ToJson());
            }

            return(isPopup ? ResultsJson(context, profiler) : ResultsFullPage(context, profiler));
        }