Joh*_*ker 6 c# asp.net global-asax
有没有办法可以从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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
页面在此处始终为null.
提前致谢.