/// <summary> /// Sets up a WebRequestProfilerProvider with the given parameters. /// This is the recommended provider for ASP.NET MVC 5 and below applications. /// Note that this registers the routes the profiler needs with the path specified /// by <paramref name="routeBasePath"/> or <see cref="MiniProfiler.Settings.RouteBasePath"/> if not provided. /// </summary> /// <param name="routeBasePath">The route path to use, e.g. "~/profiler"</param> /// <param name="resultsAuthorize">The function to use to authorize a request to access a result. See <see cref="MiniProfilerWebSettings.ResultsAuthorize"/> for details.</param> /// <param name="resultsListAuthorize">The function to use to authorize a request to access the list of results. See <see cref="MiniProfilerWebSettings.ResultsListAuthorize"/> for details.</param> /// <returns>The setup <see cref="WebRequestProfilerProvider"/> for use if needed.</returns> public static WebRequestProfilerProvider Setup( string routeBasePath = null, Func <HttpRequest, bool> resultsAuthorize = null, Func <HttpRequest, bool> resultsListAuthorize = null) { var result = new WebRequestProfilerProvider(); if (routeBasePath.HasValue()) { MiniProfiler.Settings.RouteBasePath = routeBasePath; } if (resultsAuthorize != null) { MiniProfilerWebSettings.ResultsAuthorize = resultsAuthorize; } if (resultsListAuthorize != null) { MiniProfilerWebSettings.ResultsListAuthorize = resultsListAuthorize; } MiniProfilerHandler.RegisterRoutes(); MiniProfiler.Settings.ProfilerProvider = result; return(result); }
/// <summary> /// Creates a MiniProfilerHandler and registers routes for it. /// </summary> /// <param name="options">The options to configure the handler with.</param> /// <returns>The configured and registered handler.</returns> public static MiniProfilerHandler Configure(MiniProfilerOptions options) { var handler = new MiniProfilerHandler(options); handler.RegisterRoutes(); return(handler); }
/// <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) { return(MiniProfilerHandler.RenderIncludes( profiler, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls, startHidden)); }
/// <summary> /// Returns the <c>css</c> and <c>javascript</c> includes needed to display the MiniProfiler results UI. /// </summary> /// <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="useExistingjQuery"> /// Should MiniProfiler attempt to load its own version of jQuery, or rely on a version previously loaded on the page? /// </param> /// <param name="samplingOnly">The sampling Only.</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( RenderPosition?position = null, bool?showTrivial = null, bool?showTimeWithChildren = null, int?maxTracesToShow = null, bool?showControls = null, bool?useExistingjQuery = null, // TODO: we need to deprecate this bool samplingOnly = false, // TODO: can we remove this? bool?startHidden = null) { return(MiniProfilerHandler.RenderIncludes( Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, showControls, startHidden)); }
/// <summary> /// Usually called internally, sometimes you may clear the routes during the apps lifecycle, /// if you do that call this to bring back mini profiler. /// </summary> public static void RegisterRoutes() { var routes = RouteTable.Routes; var handler = new MiniProfilerHandler(); var prefix = MiniProfiler.Settings.RouteBasePath.Replace("~/", string.Empty).EnsureTrailingSlash(); using (routes.GetWriteLock()) { var route = new Route(prefix + "{filename}", handler) { // specify these, so no MVC route helpers will match, e.g. @Html.ActionLink("Home", "Index", "Home") Defaults = new RouteValueDictionary(new { controller = "MiniProfilerHandler", action = "ProcessRequest" }), Constraints = new RouteValueDictionary(new { controller = "MiniProfilerHandler", action = "ProcessRequest" }) }; // put our routes at the beginning, like a boss routes.Insert(0, route); } }
/// <summary> /// Configures the <see cref="MiniProfilerHandler"/>. /// </summary> protected override void OnConfigure() { MiniProfilerHandler.Configure(this); }
/// <summary> /// Initialises a new instance of the <see cref="WebRequestProfilerProvider"/> class. /// Public constructor. This also registers any UI routes needed to display results /// </summary> public WebRequestProfilerProvider() { MiniProfilerHandler.RegisterRoutes(); }