I have a single page javascript application (done with JavascriptMvc) and a backend with REST services built on top of ASP.NET MVC3 (done with NServiceMVC).
The REST services have MiniProfiler installed and running, and the X-MiniProfiler-Ids headers come back with each AJAX request. I do actually have miniprofiler running and working, but I could not find any info on this, and so I am not sure if I'm doing it the right way.
Is this a supported scenario, and is there a specific way to do this now?
What I am currently doing is this:
In the HTML app (which is all static code, no dynamic stuff), I have:
<script type="text/javascript" src="/api/profiler"></script>
In my MVC app, I have:
public ActionResult Profiler()
{
if (!ControllerContext.HttpContext.IsDebuggingEnabled)
{
return new EmptyResult();
}
return new ContentResult() {
Content = StackExchange.Profiling.MiniProfiler.RenderIncludes(
position: RenderPosition.Right,
showControls: true
)
.ToString()
.Replace("<script type=\"text/javascript\">", "")
.Replace("</script>", "")
};
}
Clearly, there is a hack in here to strip out the hardcoded <script>
tags.
Other than this, from the rest of the MVC side of things, profiler is used exactly the same as usual. When you do an action in the app that causes a REST call to happen, miniprofiler shows it up in the corner. Using the showControls:true
parameter is pretty helpful here too so the clear button shows up, because otherwise you just get a constant list of actions since the entire page essentially never refreshes.
Is this the "correct" way to do this, or is there a better way?
.replace()
hack and make this the real "official" way. – Boa