/// <summary> /// Renders script tag for including MiniProfiler. /// </summary> /// <param name="profiler">The profiler to render a tag for.</param> /// <param name="context">The <see cref="HttpContext"/> this tag is being rendered in.</param> /// <param name="position">The UI position to render the profiler in (defaults to <see cref="MiniProfilerBaseOptions.PopupRenderPosition"/>).</param> /// <param name="showTrivial">Whether to show trivial timings column initially or not (defaults to <see cref="MiniProfilerBaseOptions.PopupShowTrivial"/>).</param> /// <param name="showTimeWithChildren">Whether to show time with children column initially or not (defaults to <see cref="MiniProfilerBaseOptions.PopupShowTimeWithChildren"/>).</param> /// <param name="maxTracesToShow">The maximum number of profilers to show (before the oldest is removed - defaults to <see cref="MiniProfilerBaseOptions.PopupMaxTracesToShow"/>).</param> /// <param name="showControls">Whether to show the controls (defaults to <see cref="MiniProfilerBaseOptions.ShowControls"/>).</param> /// <param name="startHidden">Whether to start hidden (defaults to <see cref="MiniProfilerBaseOptions.PopupStartHidden"/>).</param> public static HtmlString RenderIncludes( this MiniProfiler profiler, HttpContext context, RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool?showControls = null, bool?startHidden = null) { if (profiler == null) { return(HtmlString.Empty); } // This is populated in Middleware by SetHeadersAndState var state = RequestState.Get(context); var path = (profiler.Options as MiniProfilerOptions)?.RouteBasePath.Value.EnsureTrailingSlash(); var result = profiler.RenderIncludes( path: context.Request.PathBase + path, isAuthorized: state?.IsAuthorized ?? false, requestIDs: state?.RequestIDs, position: position, showTrivial: showTrivial, showTimeWithChildren: showTimeWithChildren, maxTracesToShow: maxTracesToShow, showControls: showControls, startHidden: startHidden); return(new HtmlString(result)); }
/// <summary> /// Returns the <c>css</c> and <c>javascript</c> includes needed to display the MiniProfiler results UI. /// </summary> /// <param name="profiler">The profiler this extension method is called on</param> /// <param name="position">Which side of the page the profiler popup button should be displayed on (defaults to left)</param> /// <param name="showTrivial">Whether to show trivial timings by default (defaults to false)</param> /// <param name="showTimeWithChildren">Whether to show time the time with children column by default (defaults to false)</param> /// <param name="maxTracesToShow">The maximum number of trace popups to show before removing the oldest (defaults to 15)</param> /// <param name="showControls">when true, shows buttons to minimize and clear MiniProfiler results</param> /// <param name="startHidden">Should the profiler start as hidden. Default to null.</param> /// <returns>Script and link elements normally; an empty string when there is no active profiling session.</returns> public static IHtmlString RenderIncludes( this MiniProfiler profiler, RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool?showControls = null, bool?startHidden = null) { if (profiler == null) { return(_empty); } var settings = profiler.Options as MiniProfilerOptions; if (settings == null) { return(_empty); } var authorized = settings.ResultsAuthorize?.Invoke(HttpContext.Current.Request) ?? true; // If we're not authroized, we're just rendering a <script> tag for no reason. if (!authorized) { return(_empty); } // unviewed ids are added to this list during Storage.Save, but we know we haven't // seen the current one yet, so go ahead and add it to the end var ids = authorized ? settings.Storage.GetUnviewedIds(profiler.User) : new List <Guid>(); ids.Add(profiler.Id); var path = VirtualPathUtility.ToAbsolute(settings.RouteBasePath).EnsureTrailingSlash(); var result = profiler.RenderIncludes( path: path, isAuthorized: authorized, requestIDs: ids, position: position, showTrivial: showTrivial, showTimeWithChildren: showTimeWithChildren, maxTracesToShow: maxTracesToShow, showControls: showControls, startHidden: startHidden); return(new HtmlString(result)); }
private string ResultsFullPage(HttpContext context, MiniProfiler profiler) { new RequestState { IsAuthorized = true }.Store(context); context.Response.ContentType = "text/html"; if (!Embedded.TryGetResource("share.html", out string template)) { return(NotFound(context, "Share.html was not found")); } var sb = new StringBuilder(template); sb.Replace("{name}", profiler.Name) .Replace("{duration}", profiler.DurationMilliseconds.ToString(CultureInfo.InvariantCulture)) .Replace("{path}", BasePath.Value.EnsureTrailingSlash()) .Replace("{json}", profiler.ToJson()) .Replace("{includes}", profiler.RenderIncludes(context).ToString()) .Replace("{version}", MiniProfiler.Settings.VersionHash); return(sb.ToString()); }