Showing posts with label mvc. Show all posts
Showing posts with label mvc. Show all posts

Tuesday, April 17, 2012

MiniProfiler for AJAX calls with ServiceStack.Net

I was surprised not to find this documented elsewhere on the Web.
ServiceStack.Net comes with a (slightly-modified) version of the MiniProfiler formerly-known-as "MVC MiniProfiler" now just referred to as "MiniProfiler" (http://miniprofiler.com) -- and it works great on their "HTML" service pages...but I wanted to get it to show on my MVC pages AND I also wanted it to update as I made JSON-formatted ajax calls to my web services.  So, here's what I did:

First, I'll here's my "_Layout.cshtml" file:
  1. You'll notice that I do RenderIncludes() before I include jquery. I had some problems doing it in the other order, all my AJAX calls were erroring.
  2. RenderIncludes() produces an HtmlEncoded string, so you end up with a bunch of < and stuff in your code, I'm wrapping it with @Html.Raw so that we get the actual raw text on the page.
That takes care of rendering the MiniProfiler for your MVC controller logic, but now we need to handle the ServiceStack.Net AJAX requests. Here's the javascript I used:

Basically, I'm grabbing the special Response header that ServiceStack adds called "X-MiniProfiler-Ids" that's a JSON-formatted array of ID numbers that correspond to MiniProfiler line-items -- then I'm telling the MiniProfiler to go get the data for those Ids.
That's it. After that, it "just works"

Monday, June 27, 2011

Weird Error Running ASP MVC 3 Site in Debug Mode

Saw this error today:

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Actually, the problem was I had edited the wrong web.config file :-)

In ASP.Net MVC, there's a web.config under the main root, and a web.config under the Views folder.

So, my tip of the day is, make sure you're editing the one you're supposed to be.