有没有什么办法可以从global.asax Application_EndRequest函数中访问页面对象?Asp.Net Global.asax访问当前请求的页面对象
我想在请求结束时设置一个标签的文本,但访问该页面证明比我想象的更困难。
这里是我的影片目前没有工作:
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());
}
}
}
页总是空在这里。
在此先感谢。
这实际上是一个好主意。它确实需要对设计进行调整,但它不保证负面投票,IMO。 – casperOne 2009-01-26 17:44:33
谢谢。我只是认为指出另一种可能没有注意到的方法是有帮助的。 – Noldorin 2009-01-26 18:05:43
好的电话Nolodorin。我认为这将是最好的主意。更好的办法是成为一个母版页,以确保标签始终在那里,因为听起来每个页面都有相同的标签。 – 2009-01-26 18:23:58