Can I use MiniProfiler to instrument an ASP.NET MVC WebApi website?
Asked Answered
K

1

8

The ASP.NET MVC website I'm working on has some (Controller-derived) "user" pages and some (ApiController-derived) "api" pages.

The site uses MiniProfiler to instrument the "user" pages, and I really like what it does. I'd like to have the same or similar functionality in the "api" pages - specifically, a record of the SQL statements that were executed, and how long everything took.

I saw this link which looked promising, where the URL of the entry point is simply entered into the browser address bar, but that's using the default view that comes out of the box with ASP.NET MVC WebApi. My own URLs return an XML document (or JSON response).

Also, I'd prefer something that will allow me to get away from the browser, since my real-life API calls are initiated by another program, and I'd like to be able to record information about a whole session rather than just a single request.

Any advice?

Kriss answered 29/7, 2013 at 15:59 Comment(0)
E
7

You can have MiniProfiler log it's results to a database instead of disposing of the results. At that point you'll be able to look back at the performance over time (against a session or an end point).

Add:

MiniProfiler.Settings.Storage = new SqlServerStorage("connection string here");

to your settings and it should start logging to the database.

Ease answered 29/7, 2013 at 16:10 Comment(6)
Thanks. This is great, but for the benefit of others I think it's best to mention that it won't automatically create a database - you need to create one and initialize it using the SQL in the constant StackExchange.Profiling.Storage.SqlServerStorage.TableCreationScript (see MiniProfiler source on GitHub). There may be documentation of that fact, but I failed to find it.Kriss
Also, this is a nice way to visualize the stored results: antonvishnyak.wordpress.com/2011/09/07/…Kriss
@GaryMcGill I've found that area of MiniProfiler is quite thin in documentation. I figured they would have automatically attempted to create the database by this point... Thanks for pointing it out!Ease
Is there any better way to do things these days?Literalminded
@Literalminded As far as I know not much has changed about this process. Is there something specific you want to see improved?Ease
I was just hoping for a nicer experience like there is for MVC without having to store in a database and/or a detailed description of using miniprofiler with webapi/angular.Literalminded

© 2022 - 2024 — McMap. All rights reserved.