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