I have a simple web form application that uses a masterpage.
I followed the instructions on how to get mini-profiler working. I get all the stats OK. Now I do not really know how to toggle it on or off.
I thought of using a query string and look for it Application_BeginRequest
- If it is there just use the profiler the whole session.... OK- Session is not loaded at that stage and if use the Application_AcquireRequestState
and a static variable it loads it many many times and the profiler does work sometimes, sometimes not and I do not know why?
The simple way I have now is.
protected void Application_BeginRequest(object sender, EventArgs e)
{
MiniProfiler profiler = null;
if (Request.QueryString["p"] != null)
{
profiler = MiniProfiler.Start();
using (profiler.Step("Application_BeginRequest"))
{
}
}
}
So that works ok but i have to add a query param on each request. Not good. I never used global.asax
before so I am not 100% sure how it all works down there.
What is the best way I can set a variable for a pre defined time so the profiler will always load when I turn it on in a secret way?
Edit and solution to my problem
protected void Application_BeginRequest(object sender, EventArgs e)
{
MiniProfiler profiler = null;
if (Request.Cookies["profiler"] != null)
{
profiler = MiniProfiler.Start();
using (profiler.Step("Application_BeginRequest"))
{
}
}
}