The MvcMiniprofiler nuget in WebMatrix (WebPages) [5 minutes]

The MVC3-guys gets a lot of fun tools, but what about us that sometimes prefer WebPages for getting things done on the web? Mostly it’s cool since we’re on the same good solid Asp.Net platform. The MvcMiniProfiler for example. I just read Scott Hanselman’s introduction to it and wanted to try on a WebPages site. It worked fine and looks very useful – easily profile the server side of any WebPages web app.

First – create a new Web Site (Razor) in Visual Studio or create a new site from template in WebMatrix and choose the StarterSite template.

Then add the MvcEasyProfiler Nuget MiniProfiler by opening the Package Manager Console in Visual Studio (Tools-Library Package Manager, Install-Package MiniProfiler). Or start your site in WebMatrix and go to the _admin page, first create a password, and then search for MiniProfiler (choose Default(all) as source for packages). Look for the most recent version (1.6 today). Install it.

Next add a new file called _PageStart.cshtml in the root of your web site. That page runs for every page request on your site. Using the RunPage() we divide code to be run before and after page code execution. Add the following code:

@{
    if (Request.IsLocal)
    {
        MvcMiniProfiler.MiniProfiler.Start();
        RunPage();
        MvcMiniProfiler.MiniProfiler.Stop();
    }
}

Then open the _SiteLayout.cshtml page. Add the following code just above the head end tag to include the necessary js scripts on your pages:

...
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>    
    @MvcMiniProfiler.MiniProfiler.RenderIncludes()
</head>

After that you have the profiler running and you can test it by opening any page.

When you like to test a particular piece of code enclose it within a profiler step like this:

@using MvcMiniProfiler
@{  
    using (MiniProfiler.Current.Step("Doing complex stuff"))
    {
        Layout = "~/_SiteLayout.cshtml";
        Page.Title = "Welcome to my Web Site!";
    }
}

And you get a nice window top left on your page with profiling data:

Read the Hanselman post to dive deeper into the possibilities.

About these ads

About joeriks

Living in the upper half of Sweden with my wife and our two kids. Happy programmer. Business and personal applications. Primarily Dotnet, mostly for the web. Much Opensource.

2 Responses to “The MvcMiniprofiler nuget in WebMatrix (WebPages) [5 minutes]”

  1. Have you tried using the MiniProfiler on an Umbraco site?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: