在 asp.net mvc 中,scott hanselman 示例显示了如何显示本地环境的迷你分析器
protected void Application_BeginRequest()
{
if (Request.IsLocal) { MiniProfiler.Start(); } //or any number of other checks, up to you
}
但是,我想更进一步,能够远程查看它,仅适用于特定的登录用户或 ips。
知道怎么做吗?
更新:我使用了以下代码:
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");
}