MVC – get some help
If you’re using MVC and you’re looking for some in-depth information on basically whats going on when you run the code then you should take a look at Miniprofiler (from the guys at StackOverflow) or Glimpse.
Miniprofiler can be added in to your solution and can give you all sorts of really useful information such as which view is currently being rendered and from which method in the controller (which is not always obvious). this can be quite a time saver if you’re not used to the codebase and just want to quickly find the ActionResult which has been hit.
To Add MiniProfiler to an MVC application install it using the Nuget Package Manager console. (you need to use the console sometimes if the package uses a Powershell script)
Once added via Nuget browse to your global.asax file and add in the following 2 methods:-
[sourcecode language=”csharp”] protected void Application_BeginRequest(){
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
[/sourcecode]
and then :-
[sourcecode language=”csharp”] protected void Application_EndRequest(){
MiniProfiler.Stop();
}
[/sourcecode]
Rebuild your code and run your application and you’ll see info being displayed by MiniProfiler in the top left hand corner as follows:-
Glimpse is a JavaScript plug-in which informs you of information such as Route Debugging which is a superb feature. Add Glimpse via Nuget and then browse to your site and add /glimpse.axd to the end of the url from your application:-
Pres enter and you’ll be taken to this screen, this nice bit here is you can drag the ‘Turn Glimpse On’ and ‘Turn Glimpse Off’ to your fav bar and just click them to do as it says on your site. (This is all done in JavaScript and has very little overhead)
After clicking on ‘Turn Glimpse On’ we see the little eyeball bottom right of the screen:-
When clicking on that you’ll see something like the following:-
Here we can drill into all sorts of information such as:-
- What route has been called
- Which view has been rendered
- Time spent to render the page and timings for each part
- Config on the server
Again go get them and you’ll have them up and running very quickly and benefit from the features they come with.