global.asax Application_EndRequest 関数内からページ オブジェクトにアクセスする方法はありますか?
リクエストの最後にラベルのテキストを設定しようとしていますが、ページにアクセスするのが思ったより難しいことがわかりました。
ここに私が持っているものがありますが、現在は機能していません:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Context.Items.Add("Request_Start_Time", DateTime.Now);
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
TimeSpan tsDuration = DateTime.Now.Subtract((DateTime)Context.Items["Request_Start_Time"]);
System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;
if (page != null)
{
Label label = page.FindControl("lblProcessingTime") as Label;
if (label != null)
{
label.Text = String.Format("Request Processing Time: {0}", tsDuration.ToString());
}
}
}
page はここでは常に null です。
前もって感謝します。