このコードを使用して、ユーザーが Application_BeginRequest および Application_AuthenticateRequest で役割を果たしているかどうかを確認しようとしましたが、機能しません。BeginRequest では、コードはヒットせず、Authenticate では一部のリクエストでヒットし、プロファイラーは表示されません。
Request.IsLocal のみをチェックすると正常に動作します。
if(Request.IsAuthenticated)
{
if(User.IsInRole("Admin");
MiniProfiler.Start();
}
アイデアや、なぜそれがうまくいかないのか、それを行うためのより良い方法はありますか?
[更新]私は awnser を受け入れましたが、うまく動かなかったので元に戻しました
次のことを行いましたが、最初はプロファイラーが表示されません。数回試行した後、シークレットモードでサイトにアクセスしようとしても表示されるようになったため、Cookie はありませんでした。
protected void Application_PostAuthorizeRequest(Object sender, EventArgs e)
{
if (User.IsInRole("Admin"))
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("RoleProfiler");
if (cookie == null)
{
cookie = new HttpCookie("RoleProfiler");
cookie.Value = "yes";
cookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(cookie);
}
}
}
そして、私はチェックしています
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("RoleProfiler");
if ((cookie != null) && (cookie.Value == "yes") )
{
MvcMiniProfiler.MiniProfiler.Start();
}
}
そして、リクエストの最後で終了します。
protected void Application_EndRequest()
{
MvcMiniProfiler.MiniProfiler.Stop();
}
[更新 2]締めくくりの質問です。これは無視してください。私は outputcache に所有されていました。