2
在asp.net MVC斯科特Hanselman的示例演示如何显示迷你探查了本地environmnet使迷你探查只有特定的用户和角色
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");
}
我怎样才能从在Global.asax当前用户? – 2013-04-09 08:31:22
用户不是Request中的类吗?我错过了一个程序集引用或我想用的吗? – 2013-04-09 08:33:37
我看到这个:context.Request.LogonUserIdentity.User,也许这个对用户有效,但是当我尝试使用这个 – 2013-04-09 08:35:17