c# - Asp.Net Global.asax access to the current requested Page object -


Can I use page objects from within a global object? ASACX Application_EndRequest Function?

I am trying to set the text of a label at the end of the request, but by reaching the page I thought it was proving more difficult than that.

Here's what's currently not working:

  Secure void Application_BeginRequest (object sender, EventArgs e) {context.Items.Add ("Request_Start_Time" , DateTime.Now); } Secure void Application_EndRequest (Object Sender, EventArgs e) {TimeSpace tsDuration = DateTime.Now.Subtract (datetime) context. ["Request_Start_Time"]); System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as the system. Web.UI.Page; If (label! Page = =) label {label label = page.FindControl ("lblProcessingTime"); If (label! = Null) {label.Text = String.Format ("Request Processing Time: {0}", tsDuration.ToString ()); Thanks in advance. 

"itemprop =" text ">

This is just a basepage It is best to create a square, so that all your pages should be heirs, then you can enter the code within the unload state of the page and there will be no problem.


Comments