Reputation: 34028
In asp.net mvc the scott hanselman example shows how to show the mini profiler for a local environmnet
protected void Application_BeginRequest()
{
if (Request.IsLocal) { MiniProfiler.Start(); } //or any number of other checks, up to you
}
But, I would like to go a step further and be able to see it remotely, only for specific logged in users, or ips.
Any idea how?
Update: I used the following code:
protected void Application_EndRequest()
{
MiniProfiler.Stop(); //stop as early as you can, even earlier with MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
}
protected void Application_PostAuthorizeRequest(object sender, EventArgs e)
{
if (!IsAuthorizedUserForMiniProfiler(this.Context))
{
MiniProfiler.Stop(discardResults: true);
}
}
private bool IsAuthorizedUserForMiniProfiler(HttpContext context)
{
if (context.User.Identity.Name.Equals("levalencia"))
return true;
else
return context.User.IsInRole("Admin");
}
Upvotes: 2
Views: 920
Reputation: 1039160
You could subscribe to the PostAuthorizeRequest
event and discard the results if the current user is not in a given role or the request is coming from a specific IP or whatever check you want:
protected void Application_BeginRequest()
{
MiniProfiler.Start();
}
protected void Application_PostAuthorizeRequest(object sender, EventArgs e)
{
if (!DoTheCheckHere(this.Context))
{
MiniProfiler.Stop(discardResults: true);
}
}
private bool DoTheCheckHere(HttpContext context)
{
// do your checks here
return context.User.IsInRole("Admin");
}
Upvotes: 8