forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniProfiler.cs
More file actions
73 lines (62 loc) · 2.21 KB
/
MiniProfiler.cs
File metadata and controls
73 lines (62 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#if !NETSTANDARD2_0
using System.Web;
using System.Web.Routing;
using ServiceStack.MiniProfiler;
using ServiceStack.MiniProfiler.UI;
using ServiceStack.Text;
//using IHtmlString = ServiceStack.MiniProfiler.IHtmlString;
namespace ServiceStack.Mvc.MiniProfiler
{
public class MiniProfilerRouteHandler : IRouteHandler
{
public MiniProfilerRouteHandler(MiniProfilerHandler miniProfilerHandler)
{
MiniProfilerHandler = miniProfilerHandler;
}
public MiniProfilerHandler MiniProfilerHandler { get; set; }
public IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext)
{
return MiniProfilerHandler;
}
}
public static class MiniProfiler
{
internal static void RegisterRoutes()
{
var urls = new[]
{
"ssr-jquip.all",
"ssr-includes.js",
"ssr-includes.css",
"ssr-includes.tmpl",
"ssr-results"
};
var routes = RouteTable.Routes;
var handler = new MiniProfilerRouteHandler(new MiniProfilerHandler());
var prefix = (Profiler.Settings.RouteBasePath ?? "").Replace("~/", "").WithTrailingSlash();
using (routes.GetWriteLock())
{
foreach (var url in urls)
{
var route = new Route(prefix + url, handler) {
// we have to specify these, so no MVC route helpers will match, e.g. @Html.ActionLink("Home", "Index", "Home")
Defaults = new RouteValueDictionary(new { controller = "MiniProfilerHandler", action = "ProcessRequest" })
};
// put our routes at the beginning, like a boss
routes.Insert(0, route);
}
}
}
public static System.Web.IHtmlString RenderIncludes(RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool xhtml = false, bool? showControls = null)
{
var path = VirtualPathUtility.ToAbsolute("~");
return MiniProfilerHandler.RenderIncludes(Profiler.Current, position, showTrivial, showTimeWithChildren, maxTracesToShow, xhtml, showControls, path)
.ToMvcHtmlString();
}
public static System.Web.Mvc.MvcHtmlString ToMvcHtmlString(this IHtmlString htmlString)
{
return System.Web.Mvc.MvcHtmlString.Create(htmlString.ToString());
}
}
}
#endif