ASP.NET 运行机制续(完结)

上一篇说到applicationInstance会执行一些列的事件。下面是我在msdn上找到有关asp.net程序生命周期相关的描述及图片

声明周期的起始

ASP.NET 应用程序的生命周期以浏览器向 Web 服务器(对于 ASP.NET 应用程序,通常为 IIS)发送请求为起点。 ASP.NET 是 Web 服务器下的 ISAPI 扩展。 Web 服务器接收到请求时,会对所请求的文件的文件扩展名进行检查,确定应由哪个 ISAPI 扩展处理该请求,然后将该请求传递给合适的 ISAPI 扩展。 ASP.NET 处理已映射到其上的文件扩展名,如 .aspx、.ascx、.ashx 和 .asmx。

ASP.NET 接收对应用程序的第一个请求

当 ASP.NET 接收到对应用程序中任何资源的第一个请求时,名为 ApplicationManager 的类会创建一个应用程序域。 应用程序域为全局变量提供应用程序隔离,并允许单独卸载每个应用程序。 在应用程序域中,将为名为 HostingEnvironment的类创建一个实例,该实例提供对有关应用程序的信息(如存储该应用程序的文件夹的名称)的访问。

ASP.NET 运行机制续(完结)_第1张图片

 

为每个请求创建 ASP.NET 核心对象

创建了应用程序域并对 HostingEnvironment 对象进行了实例化之后,ASP.NET 将创建并初始化核心对象,如 HttpContextHttpRequest 和 HttpResponse。 HttpContext 类包含特定于当前应用程序请求的对象,如 HttpRequest 和HttpResponse 对象。 HttpRequest 对象包含有关当前请求的信息,包括 Cookie 和浏览器信息。 HttpResponse 对象包含发送到客户端的响应,包括所有呈现的输出和 Cookie。

将 HttpApplication 对象分配给请求

初始化所有核心应用程序对象之后,将通过创建 HttpApplication 类的实例启动应用程序。 如果应用程序具有 Global.asax 文件,则 ASP.NET 会创建 Global.asax 类(从 HttpApplication 类派生)的一个实例,并使用该派生类表示应用程序。

注意注意
第一次在应用程序中请求 ASP.NET 页或进程时,将创建 HttpApplication 的一个新实例。不过,为了尽可能提高性能,可对多个请求重复使用 HttpApplication 实例。

创建 HttpApplication 的实例时,将同时创建所有已配置的模块。 例如,如果将应用程序这样配置,ASP.NET 就会创建一个 SessionStateModule 模块。 创建了所有已配置的模块之后,将调用HttpApplication 类的 Init 方法。

ASP.NET 运行机制续(完结)_第2张图片

 

由 HttpApplication 管线处理请求。

在处理该请求时将由 HttpApplication 类执行以下事件。 希望扩展 HttpApplication 类的开发人员尤其需要注意这些事件。

  1. 对请求进行验证,将检查浏览器发送的信息,并确定其是否包含潜在恶意标记。 有关更多信息,请参见 ValidateRequest 和脚本侵入概述

  2. 如果已在 Web.config 文件的 UrlMappingsSection 节中配置了任何 URL,则执行 URL 映射。

  3. 引发 BeginRequest 事件;第一个事件

  4. 引发 AuthenticateRequest 事件;验证请求,开始检查用户的身份,一把是获取请求的用户信息

  5. 引发 PostAuthenticateRequest 事件;用户身份已经检查完毕,检查完成后可以通过HttpContext的User属性获取到,微软内置的身份验证机制,平时很少用到

  6. 引发 AuthorizeRequest 事件;开始进行用户权限检查,如果用户没有通过上面的安全检查,一般会直接调至EndRequest事件,也就是直接跳至最后一个事件

  7. 引发 PostAuthorizeRequest 事件;用户请求已经获取授权

  8. 引发 ResolveRequestCache 事件;缓存,如果存在以前处理的缓存结果,则不再进行请求处理工作,返回缓存结果

  9. 引发 PostResolveRequestCache 事件;缓存检查结束

  10. 根据所请求资源的文件扩展名(在应用程序的配置文件中映射),选择实现 IHttpHandler 的类,对请求进行处理。 如果该请求针对从 Page 类派生的对象(页),并且需要对该页进行编译,则 ASP.NET 会在创建该页的实例之前对其进行编译;创建所请求的前台页面类

  11. 引发 PostMapRequestHandler 事件;已经创建处理请求的处理器对象(IHttpHandler)

  12. 引发 AcquireRequestState 事件;获取请求状态,一般用于获取session

  13. 引发 PostAcquireRequestState 事件。已经获取到了session,如果获取到,则将session的值封装到httpcontext中的session属性中去,

  14. 引发 PreRequestHandlerExecute 事件。以为上个事件已经封装了session信息,所以接下来就是验证身份信息的最好位置,如果不通过,直接处理,提高效率。这里也是准备执行处理程序,及调用HttpContext中Handler属性的ProcessRequest

  15. 为该请求调用合适的 IHttpHandler 类的 ProcessRequest 方法(或异步版 IHttpAsyncHandler.BeginProcessRequest)。 例如,如果该请求针对某页,则当前的页实例将处理该请求。

  16. 引发 PostRequestHandlerExecute 事件;页面的ProcessRequest方法执行完成

  17. 引发 ReleaseRequestState 事件;准备释放请求状态session

  18. 引发 PostReleaseRequestState 事件;已经释放请求状态

  19. 如果定义了 Filter 属性,则执行响应筛选。

  20. 引发 UpdateRequestCache 事件;更新缓存

  21. 引发 PostUpdateRequestCache 事件;更新缓存完毕

  22. 引发 EndRequest 事件;结束请求

  23. 引发 PreSendRequestHeaders 事件;可通过发送的头信息设置参数,例如将类型设置为text/plain等

  24. 引发 PreSendRequestContent 事件;处理数据,如配置压缩,则可在这里对数据进行压缩发送

好了,不贴人家的东西了,感兴趣的可以到原网站去看一下。我们重点就是看一下HttpApplication管线处理请求。下面是对事件的解释

 
  名称 说明
公共事件 AcquireRequestState 当 ASP.NET 获取与当前请求关联的当前状态(如会话状态)时发生。
公共事件 AuthenticateRequest 当安全模块已建立用户标识时发生。
公共事件 AuthorizeRequest 当安全模块已验证用户授权时发生。
公共事件 BeginRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的第一个事件发生。
公共事件 Disposed 在释放应用程序时发生。
公共事件 EndRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的最后一个事件发生。
公共事件 Error 当引发未经处理的异常时发生。
公共事件 LogRequest 恰好在 ASP.NET 为当前请求执行任何记录之前发生。
公共事件 MapRequestHandler 基础结构。在选择了用来响应请求的处理程序时发生。
公共事件 PostAcquireRequestState 在已获得与当前请求关联的请求状态(例如会话状态)时发生。
公共事件 PostAuthenticateRequest 当安全模块已建立用户标识时发生。
公共事件 PostAuthorizeRequest 在当前请求的用户已获授权时发生。
公共事件 PostLogRequest 在 ASP.NET 处理完 LogRequest 事件的所有事件处理程序后发生。
公共事件 PostMapRequestHandler 在 ASP.NET 已将当前请求映射到相应的事件处理程序时发生。
公共事件 PostReleaseRequestState 在 ASP.NET 已完成所有请求事件处理程序的执行并且请求状态数据已存储时发生。
公共事件 PostRequestHandlerExecute 在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生。
公共事件 PostResolveRequestCache 在 ASP.NET 跳过当前事件处理程序的执行并允许缓存模块满足来自缓存的请求时发生。
公共事件 PostUpdateRequestCache 在 ASP.NET 完成缓存模块的更新并存储了用于从缓存中为后续请求提供服务的响应后,发生此事件。
公共事件 PreRequestHandlerExecute 恰好在 ASP.NET 开始执行事件处理程序(例如,某页或某个 XML Web services)前发生。
公共事件 PreSendRequestContent 恰好在 ASP.NET 向客户端发送内容之前发生。
公共事件 PreSendRequestHeaders 恰好在 ASP.NET 向客户端发送 HTTP 标头之前发生。
公共事件 ReleaseRequestState 在 ASP.NET 执行完所有请求事件处理程序后发生。 该事件将使状态模块保存当前状态数据。
公共事件 RequestCompleted 发生,在与该请求已释放的托管对象。
公共事件 ResolveRequestCache 在 ASP.NET 完成授权事件以使缓存模块从缓存中为请求提供服务后发生,从而绕过事件处理程序(例如某个页或 XML Web services)的执行。
公共事件 UpdateRequestCache 当 ASP.NET 执行完事件处理程序以使缓存模块存储将用于从缓存为后续请求提供服务的响应时发生。

看一下上面的管线处理请求中标号的10和15,分别是创建前台页面类和调用页面类的ProcessRequest方法的地方。这在我们的上篇文章中说到了。下面我们重点说Application_Start方法执行的地方,ProcessRequest方法都做了什么。

我们都知道Application_Start是程序的入口地方,类似与我们的main函数。但是我在msdn上也没能查到Application_Start是在哪里调用了,但是我们似乎是可以找到这个方法调用的地方,让我们来反编译HttpRuntime(为什么选择反编译这个类?上篇文章里面会有答案)的ProcessRequestNow()方法,继续看_theRuntime.ProcessRequestInternal(wr);我们看ProcessRequestInternal方法中的IHttpHandler applicationInstance = HttpApplicationFactory.GetApplicationInstance(context);,我们可以看出来HttpApplicationFactory是个静态类,我们可以看到该静态类里面有成员internal const string applicationFileName = "global.asax";private static HttpApplicationFactory _theApplicationFactory;private bool _appOnStartCalled;这里我们知道了为什么global.asax文件为什么不能修改文件名,因为这里已经写死了。而后面_appOnStartCalled变量记录着程序的application_start方法是否被调用过,如没被调用过,则为false,进而调用程序的application_start,反之则不进行调用。看GetApplicationInstance中会有判断过程_theApplicationFactory.EnsureAppStartCalled(context);。所以程序的Application_Start()方法的执行顺序肯定先于所有的管线处理请求中的事件。

下面我们来看一下页面的ProcessRequest方法都做了什么操作。也就是开始页面生命周期。

我新建了一个ReflectWeb项目,又添加了demo.aspx页面,页面内容如下

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="ReflectorWeb.Demo" %>
 2 
 3 <!DOCTYPE html>
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 8     <title></title>
 9 </head>
10 <body>
11     <form id="form1" runat="server">
12     <div>
13         程序集位置:<%=this.GetType().Assembly.Location %><br />
14         TextBox1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
15         TextBox2:<input type="text" runat="server" id="TextBox2" /><br />
16         TextBox3:<input type="text" id="TextBox3" /><br />
17     </div>
18     </form>
19 </body>
20 </html>
View Code

后台类内容很简单

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 namespace ReflectorWeb
 9 {
10     public partial class Demo : System.Web.UI.Page
11     {
12         protected void Page_Load(object sender, EventArgs e)
13         {
14             Console.WriteLine("test console");
15             //byte[] tempData = System.Text.Encoding.UTF8.GetBytes("测试Page_Load方法中使用Response.Write方法输出");
16             Response.Write("测试Page_Load方法中使用Response.Write方法输出");
17         }
18     }
19 }
View Code

而页面效果如下

ASP.NET 运行机制续(完结)_第3张图片

下面我们来反编译一下这个程序集,看一下这个程序集里面的内容

ASP.NET 运行机制续(完结)_第4张图片

程序集里面有个demo_aspx类,这就是我们前台页面生成后的类了,页面类代码如下:

 1 [CompilerGlobalScope]
 2 public class demo_aspx : Demo, IRequiresSessionState, IHttpHandler
 3 {
 4     // Fields
 5     private static object __fileDependencies;
 6     private static bool __initialized;
 7     private static MethodInfo __PageInspector_BeginRenderTracingMethod;
 8     private static MethodInfo __PageInspector_EndRenderTracingMethod;
 9     private static MethodInfo __PageInspector_SetTraceDataMethod;
10 
11     // Methods
12     static demo_aspx();
13     [DebuggerNonUserCode]
14     public demo_aspx();
15     [DebuggerNonUserCode]
16     private LiteralControl __BuildControl__control2();
17     [DebuggerNonUserCode]
18     private HtmlHead __BuildControl__control3();
19     [DebuggerNonUserCode]
20     private HtmlMeta __BuildControl__control4();
21     [DebuggerNonUserCode]
22     private HtmlTitle __BuildControl__control5();
23     [DebuggerNonUserCode]
24     private LiteralControl __BuildControl__control6();
25     [DebuggerNonUserCode]
26     private LiteralControl __BuildControl__control7();
27     [DebuggerNonUserCode]
28     private HtmlForm __BuildControlform1();
29     [DebuggerNonUserCode]
30     private TextBox __BuildControlTextBox1();
31     [DebuggerNonUserCode]
32     private HtmlInputText __BuildControlTextBox2();
33     [DebuggerNonUserCode]
34     private void __BuildControlTree(demo_aspx __ctrl);
35     private void __PageInspector_BeginRenderTracing(object[] parameters);
36     private void __PageInspector_EndRenderTracing(object[] parameters);
37     private static MethodInfo __PageInspector_LoadHelper(string helperName);
38     private void __PageInspector_SetTraceData(object[] parameters);
39     private void __Renderform1(HtmlTextWriter __w, Control parameterContainer);
40     [DebuggerNonUserCode]
41     protected override void FrameworkInitialize();
42     [DebuggerNonUserCode]
43     public override int GetTypeHashCode();
44     [DebuggerNonUserCode]
45     public override void ProcessRequest(HttpContext context);
46 
47     // Properties
48     protected HttpApplication ApplicationInstance { get; }
49     protected DefaultProfile Profile { get; }
50 }
51 
52  
53 Expand Methods
54  
View Code

注意一下,该类继承自Demo类,也就是后台类,而后台类又继承自Page类。下面进入ProcessRequest方法 又调用了父类的ProcessRequest方法base.ProcessRequest(context);这个Page类的一个方法,看这个类的组成

  1 [Designer("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, Microsoft.VisualStudio.Web, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(IRootDesigner)), DefaultEvent("Load"), ToolboxItem(false), DesignerCategory("ASPXCodeBehind"), DesignerSerializer("Microsoft.VisualStudio.Web.WebForms.WebFormCodeDomSerializer, Microsoft.VisualStudio.Web, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.Serialization.TypeCodeDomSerializer, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  2 public class Page : TemplateControl, IHttpHandler
  3 {
  4     // Fields
  5     internal HttpApplicationState _application;
  6     private bool _aspCompatMode;
  7     private AspCompatApplicationStep _aspCompatStep;
  8     private bool _asyncMode;
  9     private PageAsyncTaskManager _asyncTaskManager;
 10     private TimeSpan _asyncTimeout;
 11     private bool _asyncTimeoutSet;
 12     private Control _autoPostBackControl;
 13     internal Cache _cache;
 14     private bool _cachedRequestViewState;
 15     private ICallbackEventHandler _callbackControl;
 16     private ArrayList _changedPostDataConsumers;
 17     private string _clientQueryString;
 18     private ClientScriptManager _clientScriptManager;
 19     private string _clientState;
 20     private bool _clientSupportsJavaScript;
 21     private bool _clientSupportsJavaScriptChecked;
 22     private string _clientTarget;
 23     private bool _containsCrossPagePost;
 24     private bool _containsEncryptedViewState;
 25     private IDictionary _contentTemplateCollection;
 26     internal HttpContext _context;
 27     private ArrayList _controlsRequiringPostBack;
 28     private StringSet _controlStateLoadedControlIds;
 29     private Stack _dataBindingContext;
 30     private string _descriptionToBeSet;
 31     private bool _designMode;
 32     private bool _designModeChecked;
 33     private CultureInfo _dynamicCulture;
 34     private CultureInfo _dynamicUICulture;
 35     private ArrayList _enabledControls;
 36     private bool _enableEventValidation;
 37     private bool _enableViewStateMac;
 38     private ViewStateEncryptionMode _encryptionMode;
 39     internal string _errorPage;
 40     private Control _focusedControl;
 41     private string _focusedControlID;
 42     private bool _fOnFormRenderCalled;
 43     private HtmlForm _form;
 44     private bool _fPageLayoutChanged;
 45     private bool _fPostBackScriptRendered;
 46     private bool _fRequirePostBackScript;
 47     private bool _fRequireWebFormsScript;
 48     private bool _fWebFormsScriptRendered;
 49     private bool _haveIdSeparator;
 50     private HtmlHead _header;
 51     internal Dictionary<string, string> _hiddenFieldsToRender;
 52     private char _idSeparator;
 53     private bool _inOnFormRender;
 54     private bool _isCallback;
 55     private bool _isCrossPagePostBack;
 56     private IDictionary _items;
 57     private string _keywordsToBeSet;
 58     private NameValueCollection _leftoverPostData;
 59     private LegacyPageAsyncInfo _legacyAsyncInfo;
 60     private LegacyPageAsyncTaskManager _legacyAsyncTaskManager;
 61     private bool _maintainScrollPosition;
 62     private MasterPage _master;
 63     private VirtualPath _masterPageFile;
 64     private static readonly TimeSpan _maxAsyncTimeout;
 65     private int _maxPageStateFieldLength;
 66     private ModelBindingExecutionContext _modelBindingExecutionContext;
 67     private ModelStateDictionary _modelState;
 68     private bool _needToPersistViewState;
 69     private PageAdapter _pageAdapter;
 70     private SimpleBitVector32 _pageFlags;
 71     private Stack _partialCachingControlStack;
 72     private PageStatePersister _persister;
 73     private RenderMethod _postFormRenderDelegate;
 74     private bool _preInitWorkComplete;
 75     private Page _previousPage;
 76     private VirtualPath _previousPagePath;
 77     private bool _profileTreeBuilt;
 78     internal HybridDictionary _registeredControlsRequiringClearChildControlState;
 79     internal ControlSet _registeredControlsRequiringControlState;
 80     private ArrayList _registeredControlsThatRequirePostBack;
 81     private IPostBackEventHandler _registeredControlThatRequireRaiseEvent;
 82     private string _relativeFilePath;
 83     internal HttpRequest _request;
 84     private NameValueCollection _requestValueCollection;
 85     private string _requestViewState;
 86     private bool _requireFocusScript;
 87     private bool _requireScrollScript;
 88     internal HttpResponse _response;
 89     private static Type _scriptManagerType;
 90     private int _scrollPositionX;
 91     private const string _scrollPositionXID = "__SCROLLPOSITIONX";
 92     private int _scrollPositionY;
 93     private const string _scrollPositionYID = "__SCROLLPOSITIONY";
 94     private HttpSessionState _session;
 95     private bool _sessionRetrieved;
 96     private SmartNavigationSupport _smartNavSupport;
 97     private PageTheme _styleSheet;
 98     private string _styleSheetName;
 99     private int _supportsStyleSheets;
100     private PageTheme _theme;
101     private string _themeName;
102     private string _titleToBeSet;
103     private int _transactionMode;
104     private string _uniqueFilePathSuffix;
105     private UnobtrusiveValidationMode? _unobtrusiveValidationMode;
106     private NameValueCollection _unvalidatedRequestValueCollection;
107     private bool _validated;
108     private string _validatorInvalidControl;
109     private ValidatorCollection _validators;
110     private bool _viewStateEncryptionRequested;
111     private string _viewStateUserKey;
112     private XhtmlConformanceMode _xhtmlConformanceMode;
113     private bool _xhtmlConformanceModeSet;
114     internal const bool BufferDefault = true;
115     internal const string callbackID = "__CALLBACKID";
116     internal const string callbackIndexID = "__CALLBACKINDEX";
117     internal const string callbackLoadScriptID = "__CALLBACKLOADSCRIPT";
118     internal const string callbackParameterID = "__CALLBACKPARAM";
119     internal static readonly int DefaultAsyncTimeoutSeconds;
120     internal static readonly int DefaultMaxPageStateFieldLength;
121     private const string EnabledControlArray = "__enabledControlArray";
122     internal const bool EnableEventValidationDefault = true;
123     internal const bool EnableViewStateMacDefault = true;
124     internal const ViewStateEncryptionMode EncryptionModeDefault = ViewStateEncryptionMode.Auto;
125     internal static readonly object EventInitComplete;
126     internal static readonly object EventLoadComplete;
127     internal static readonly object EventPreInit;
128     internal static readonly object EventPreLoad;
129     internal static readonly object EventPreRenderComplete;
130     internal static readonly object EventSaveStateComplete;
131     internal const string EventValidationPrefixID = "__EVENTVALIDATION";
132     private static readonly Version FocusMinimumEcmaVersion;
133     private static readonly Version FocusMinimumJScriptVersion;
134     private const string HiddenClassName = "aspNetHidden";
135     private const int isCrossPagePostRequest = 8;
136     private const int isExportingWebPart = 2;
137     private const int isExportingWebPartShared = 4;
138     private const int isPartialRenderingSupported = 0x10;
139     private const int isPartialRenderingSupportedSet = 0x20;
140     private static readonly Version JavascriptMinimumVersion;
141     private const string lastFocusID = "__LASTFOCUS";
142     internal const bool MaintainScrollPositionOnPostBackDefault = false;
143     private static readonly Version MSDomScrollMinimumVersion;
144     private const string PageID = "__Page";
145     private const string PageReEnableControlsScriptKey = "PageReEnableControlsScript";
146     private const string PageRegisteredControlsThatRequirePostBackKey = "__ControlsRequirePostBackKey__";
147     private const string PageScrollPositionScriptKey = "PageScrollPositionScript";
148     private const string PageSubmitScriptKey = "PageSubmitScript";
149     [EditorBrowsable(EditorBrowsableState.Never)]
150     public const string postEventArgumentID = "__EVENTARGUMENT";
151     [EditorBrowsable(EditorBrowsableState.Never)]
152     public const string postEventSourceID = "__EVENTTARGET";
153     internal const string previousPageID = "__PREVIOUSPAGE";
154     private static StringSet s_systemPostFields;
155     private static char[] s_varySeparator;
156     private const int skipFormActionValidation = 0x40;
157     internal const bool SmartNavigationDefault = false;
158     private const int styleSheetInitialized = 1;
159     internal const string systemPostFieldPrefix = "__";
160     private static readonly string UniqueFilePathSuffixID;
161     internal const string ViewStateEncryptionID = "__VIEWSTATEENCRYPTED";
162     internal const string ViewStateFieldCountID = "__VIEWSTATEFIELDCOUNT";
163     internal const string ViewStateFieldPrefixID = "__VIEWSTATE";
164     internal const string WebPartExportID = "__WEBPARTEXPORT";
165 
166     // Events
167     [EditorBrowsable(EditorBrowsableState.Advanced)]
168     public event EventHandler InitComplete;
169     [EditorBrowsable(EditorBrowsableState.Advanced)]
170     public event EventHandler LoadComplete;
171     public event EventHandler PreInit;
172     [EditorBrowsable(EditorBrowsableState.Advanced)]
173     public event EventHandler PreLoad;
174     [EditorBrowsable(EditorBrowsableState.Advanced)]
175     public event EventHandler PreRenderComplete;
176     [EditorBrowsable(EditorBrowsableState.Advanced)]
177     public event EventHandler SaveStateComplete;
178 
179     // Methods
180     static Page();
181     public Page();
182     [EditorBrowsable(EditorBrowsableState.Never)]
183     protected internal void AddContentTemplate(string templateName, ITemplate template);
184     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
185     public void AddOnPreRenderCompleteAsync(BeginEventHandler beginHandler, EndEventHandler endHandler);
186     public void AddOnPreRenderCompleteAsync(BeginEventHandler beginHandler, EndEventHandler endHandler, object state);
187     [EditorBrowsable(EditorBrowsableState.Never)]
188     protected internal void AddWrappedFileDependencies(object virtualFileDependencies);
189     internal void ApplyControlSkin(Control ctrl);
190     [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
191     internal bool ApplyControlStyleSheet(Control ctrl);
192     private void ApplyMasterPage();
193     [EditorBrowsable(EditorBrowsableState.Never)]
194     protected IAsyncResult AspCompatBeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData);
195     [EditorBrowsable(EditorBrowsableState.Never)]
196     protected void AspCompatEndProcessRequest(IAsyncResult result);
197     [EditorBrowsable(EditorBrowsableState.Never)]
198     protected IAsyncResult AsyncPageBeginProcessRequest(HttpContext context, AsyncCallback callback, object extraData);
199     [EditorBrowsable(EditorBrowsableState.Never)]
200     protected void AsyncPageEndProcessRequest(IAsyncResult result);
201     private void AsyncPageProcessRequestBeforeAsyncPointCancellableCallback(object state);
202     internal void BeginFormRender(HtmlTextWriter writer, string formUniqueID);
203     private void BuildPageProfileTree(bool enableViewState);
204     private void CheckRemainingAsyncTasks(bool isThreadAbort);
205     private CancellationTokenSource CreateCancellationTokenFromAsyncTimeout();
206     [EditorBrowsable(EditorBrowsableState.Advanced)]
207     protected internal virtual HtmlTextWriter CreateHtmlTextWriter(TextWriter tw);
208     public static HtmlTextWriter CreateHtmlTextWriterFromType(TextWriter tw, Type writerType);
209     internal static HtmlTextWriter CreateHtmlTextWriterInternal(TextWriter tw, HttpRequest request);
210     internal IStateFormatter2 CreateStateFormatter();
211     private CultureInfo CultureFromUserLanguages(bool specific);
212     internal ICollection DecomposeViewStateIntoChunks();
213     internal static string DecryptString(string s, Purpose purpose);
214     [EditorBrowsable(EditorBrowsableState.Never)]
215     public void DesignerInitialize();
216     private bool DetermineIsExportingWebPart();
217     [EditorBrowsable(EditorBrowsableState.Advanced)]
218     protected internal virtual NameValueCollection DeterminePostBackMode();
219     [EditorBrowsable(EditorBrowsableState.Advanced)]
220     protected internal virtual NameValueCollection DeterminePostBackModeUnvalidated();
221     internal static string EncryptString(string s, Purpose purpose);
222     internal void EndFormRender(HtmlTextWriter writer, string formUniqueID);
223     internal void EndFormRenderArrayAndExpandoAttribute(HtmlTextWriter writer, string formUniqueID);
224     internal void EndFormRenderHiddenFields(HtmlTextWriter writer, string formUniqueID);
225     internal void EndFormRenderPostBackAndWebFormsScript(HtmlTextWriter writer, string formUniqueID);
226     public void ExecuteRegisteredAsyncTasks();
227     private void ExportWebPart(string exportedWebPartID);
228     public override Control FindControl(string id);
229     protected override void FrameworkInitialize();
230     internal NameValueCollection GetCollectionBasedOnMethod(bool dontReturnNull);
231     public object GetDataItem();
232     internal bool GetDesignModeInternal();
233     [Obsolete("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Advanced)]
234     public string GetPostBackClientEvent(Control control, string argument);
235     [EditorBrowsable(EditorBrowsableState.Advanced), Obsolete("The recommended alternative is ClientScript.GetPostBackClientHyperlink. http://go.microsoft.com/fwlink/?linkid=14202")]
236     public string GetPostBackClientHyperlink(Control control, string argument);
237     [Obsolete("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Advanced)]
238     public string GetPostBackEventReference(Control control);
239     [Obsolete("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Advanced)]
240     public string GetPostBackEventReference(Control control, string argument);
241     [EditorBrowsable(EditorBrowsableState.Never)]
242     public virtual int GetTypeHashCode();
243     internal override string GetUniqueIDPrefix();
244     public ValidatorCollection GetValidators(string validationGroup);
245     internal WithinCancellableCallbackTaskAwaitable GetWaitForPreviousStepCompletionAwaitable();
246     [EditorBrowsable(EditorBrowsableState.Never)]
247     protected object GetWrappedFileDependencies(string[] virtualFileDependencies);
248     private bool HandleError(Exception e);
249     protected virtual void InitializeCulture();
250     internal void InitializeStyleSheet();
251     private void InitializeThemes();
252     private void InitializeWriter(HtmlTextWriter writer);
253     [EditorBrowsable(EditorBrowsableState.Never)]
254     protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings);
255     [EditorBrowsable(EditorBrowsableState.Never), TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
256     protected virtual void InitOutputCache(int duration, string varyByHeader, string varyByCustom, OutputCacheLocation location, string varyByParam);
257     [EditorBrowsable(EditorBrowsableState.Never)]
258     protected virtual void InitOutputCache(int duration, string varyByContentEncoding, string varyByHeader, string varyByCustom, OutputCacheLocation location, string varyByParam);
259     [Obsolete("The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). http://go.microsoft.com/fwlink/?linkid=14202")]
260     public bool IsClientScriptBlockRegistered(string key);
261     [Obsolete("The recommended alternative is ClientScript.IsStartupScriptRegistered(string key). http://go.microsoft.com/fwlink/?linkid=14202")]
262     public bool IsStartupScriptRegistered(string key);
263     internal static bool IsSystemPostField(string field);
264     private IAsyncResult LegacyAsyncPageBeginProcessRequest(HttpContext context, AsyncCallback callback, object extraData);
265     private void LegacyAsyncPageEndProcessRequest(IAsyncResult result);
266     private void LoadAllState();
267     [EditorBrowsable(EditorBrowsableState.Advanced)]
268     protected internal virtual object LoadPageStateFromPersistenceMedium();
269     internal void LoadScrollPosition();
270     public string MapPath(string virtualPath);
271     internal void OnFormPostRender(HtmlTextWriter writer);
272     internal void OnFormRender();
273     protected internal override void OnInit(EventArgs e);
274     protected virtual void OnInitComplete(EventArgs e);
275     protected virtual void OnLoadComplete(EventArgs e);
276     protected virtual void OnPreInit(EventArgs e);
277     protected virtual void OnPreLoad(EventArgs e);
278     protected virtual void OnPreRenderComplete(EventArgs e);
279     protected virtual void OnSaveStateComplete(EventArgs e);
280     private void PerformPreInit();
281     [DebuggerStepThrough, AsyncStateMachine(typeof(<PerformPreInitAsync>d__c))]
282     private Task PerformPreInitAsync();
283     private void PerformPreRenderComplete();
284     internal void PopCachingControl();
285     internal void PopDataBindingContext();
286     private void PrepareCallback(string callbackControlID);
287     [AsyncStateMachine(typeof(<PrepareCallbackAsync>d__1f)), DebuggerStepThrough]
288     private Task PrepareCallbackAsync(string callbackControlID);
289     private void ProcessPostData(NameValueCollection postData, bool fBeforeLoad);
290     private void ProcessRequest();
291     [EditorBrowsable(EditorBrowsableState.Never)]
292     public virtual void ProcessRequest(HttpContext context);
293     private void ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint);
294     [AsyncStateMachine(typeof(<ProcessRequestAsync>d__2c)), DebuggerStepThrough]
295     private Task ProcessRequestAsync(HttpContext context);
296     [DebuggerStepThrough, AsyncStateMachine(typeof(<ProcessRequestAsync>d__10))]
297     private Task ProcessRequestAsync(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint);
298     private void ProcessRequestCleanup();
299     private void ProcessRequestEndTrace();
300     private void ProcessRequestMain();
301     private void ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint);
302     [DebuggerStepThrough, AsyncStateMachine(typeof(<ProcessRequestMainAsync>d__14))]
303     private Task ProcessRequestMainAsync(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint);
304     private void ProcessRequestTransacted();
305     [PermissionSet(SecurityAction.Assert, Unrestricted=true)]
306     private void ProcessRequestWithAssert(HttpContext context);
307     private void ProcessRequestWithNoAssert(HttpContext context);
308     internal void PushCachingControl(BasePartialCachingControl c);
309     internal void PushDataBindingContext(object dataItem);
310     internal void RaiseChangedEvents();
311     [DebuggerStepThrough, AsyncStateMachine(typeof(<RaiseChangedEventsAsync>d__5))]
312     internal Task RaiseChangedEventsAsync();
313     private void RaisePostBackEvent(NameValueCollection postData);
314     [EditorBrowsable(EditorBrowsableState.Advanced)]
315     protected virtual void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument);
316     [Obsolete("The recommended alternative is ClientScript.RegisterArrayDeclaration(string arrayName, string arrayValue). http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Advanced)]
317     public void RegisterArrayDeclaration(string arrayName, string arrayValue);
318     public void RegisterAsyncTask(PageAsyncTask task);
319     [Obsolete("The recommended alternative is ClientScript.RegisterClientScriptBlock(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Advanced)]
320     public virtual void RegisterClientScriptBlock(string key, string script);
321     internal void RegisterEnabledControl(Control control);
322     internal void RegisterFocusScript();
323     [EditorBrowsable(EditorBrowsableState.Advanced), Obsolete("The recommended alternative is ClientScript.RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue). http://go.microsoft.com/fwlink/?linkid=14202")]
324     public virtual void RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue);
325     [Obsolete("The recommended alternative is ClientScript.RegisterOnSubmitStatement(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Advanced)]
326     public void RegisterOnSubmitStatement(string key, string script);
327     internal void RegisterPostBackScript();
328     internal void RegisterRequiresClearChildControlState(Control control);
329     [EditorBrowsable(EditorBrowsableState.Advanced)]
330     public void RegisterRequiresControlState(Control control);
331     [EditorBrowsable(EditorBrowsableState.Advanced)]
332     public void RegisterRequiresPostBack(Control control);
333     [EditorBrowsable(EditorBrowsableState.Advanced)]
334     public virtual void RegisterRequiresRaiseEvent(IPostBackEventHandler control);
335     public void RegisterRequiresViewStateEncryption();
336     [EditorBrowsable(EditorBrowsableState.Advanced), Obsolete("The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202")]
337     public virtual void RegisterStartupScript(string key, string script);
338     [EditorBrowsable(EditorBrowsableState.Advanced)]
339     public void RegisterViewStateHandler();
340     internal void RegisterWebFormsScript();
341     protected internal override void Render(HtmlTextWriter writer);
342     private void RenderCallback();
343     private bool RenderDivAroundHiddenInputs(HtmlTextWriter writer);
344     private void RenderPostBackScript(HtmlTextWriter writer, string formUniqueID);
345     internal void RenderViewStateFields(HtmlTextWriter writer);
346     private void RenderWebFormsScript(HtmlTextWriter writer);
347     public bool RequiresControlState(Control control);
348     internal void ResetOnFormRenderCalled();
349     private void RestoreCultures(Thread currentThread, CultureInfo prevCulture, CultureInfo prevUICulture);
350     private void SaveAllState();
351     [EditorBrowsable(EditorBrowsableState.Advanced)]
352     protected internal virtual void SavePageStateToPersistenceMedium(object state);
353     internal void SetActiveValueProvider(IValueProvider valueProvider);
354     private void SetCulture(Thread currentThread, CultureInfo currentCulture, CultureInfo currentUICulture);
355     [SecurityPermission(SecurityAction.Assert, ControlThread=true)]
356     private void SetCultureWithAssert(Thread currentThread, CultureInfo currentCulture, CultureInfo currentUICulture);
357     public void SetFocus(string clientID);
358     public void SetFocus(Control control);
359     internal void SetForm(HtmlForm form);
360     internal void SetHeader(HtmlHead header);
361     private void SetIntrinsics(HttpContext context);
362     private void SetIntrinsics(HttpContext context, bool allowAsync);
363     internal void SetPostFormRenderDelegate(RenderMethod renderMethod);
364     internal void SetPreviousPage(Page previousPage);
365     internal void SetValidatorInvalidControlFocus(string clientID);
366     internal bool ShouldLoadControlState(Control control);
367     [SecurityPermission(SecurityAction.Assert, ControlThread=true)]
368     internal static void ThreadResetAbortWithAssert();
369     public virtual bool TryUpdateModel<TModel>(TModel model) where TModel: class;
370     public virtual bool TryUpdateModel<TModel>(TModel model, IValueProvider valueProvider) where TModel: class;
371     internal override void UnloadRecursive(bool dispose);
372     [EditorBrowsable(EditorBrowsableState.Advanced)]
373     public void UnregisterRequiresControlState(Control control);
374     public virtual void UpdateModel<TModel>(TModel model) where TModel: class;
375     public virtual void UpdateModel<TModel>(TModel model, IValueProvider valueProvider) where TModel: class;
376     public virtual void Validate();
377     public virtual void Validate(string validationGroup);
378     private void ValidateRawUrlIfRequired();
379     [EditorBrowsable(EditorBrowsableState.Advanced)]
380     public virtual void VerifyRenderingInServerForm(Control control);
381 
382     // Properties
383     private IValueProvider ActiveValueProvider { [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [CompilerGenerated] set; }
384     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
385     public HttpApplicationState Application { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
386     [EditorBrowsable(EditorBrowsableState.Never)]
387     protected bool AspCompatMode { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
388     [EditorBrowsable(EditorBrowsableState.Never)]
389     protected bool AsyncMode { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
390     [Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
391     public TimeSpan AsyncTimeout { get; set; }
392     public Control AutoPostBackControl { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
393     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
394     public bool Buffer { get; set; }
395     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
396     public Cache Cache { get; }
397     internal string ClientOnSubmitEvent { get; }
398     public string ClientQueryString { get; }
399     public ClientScriptManager ClientScript { get; }
400     internal string ClientState { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
401     internal bool ClientSupportsFocus { get; }
402     internal bool ClientSupportsJavaScript { get; }
403     [WebSysDescription("Page_ClientTarget"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(""), Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced)]
404     public string ClientTarget { get; set; }
405     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
406     public int CodePage { get; set; }
407     internal bool ContainsCrossPagePost { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
408     internal bool ContainsEncryptedViewState { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
409     internal bool ContainsTheme { get; }
410     [EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
411     public string ContentType { get; set; }
412     protected internal override HttpContext Context { [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] get; }
413     private StringSet ControlStateLoadedControlIds { get; }
414     [Browsable(false), EditorBrowsable(EditorBrowsableState.Advanced), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
415     public string Culture { get; set; }
416     internal CultureInfo DynamicCulture { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
417     internal CultureInfo DynamicUICulture { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
418     private ArrayList EnabledControls { get; }
419     [DefaultValue(true), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
420     public virtual bool EnableEventValidation { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
421     [Browsable(false)]
422     public override bool EnableViewState { get; set; }
423     [EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
424     public bool EnableViewStateMac { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
425     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), WebSysDescription("Page_ErrorPage"), DefaultValue("")]
426     public string ErrorPage { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
427     [Obsolete("The recommended alternative is HttpResponse.AddFileDependencies. http://go.microsoft.com/fwlink/?linkid=14202"), EditorBrowsable(EditorBrowsableState.Never)]
428     protected ArrayList FileDependencies { set; }
429     internal Control FocusedControl { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
430     internal string FocusedControlID { get; }
431     public HtmlForm Form { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
432     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
433     public HtmlHead Header { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
434     [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
435     public override string ID { get; set; }
436     [EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
437     public virtual char IdSeparator { get; }
438     public bool IsAsync { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
439     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
440     public bool IsCallback { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
441     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
442     public bool IsCrossPagePostBack { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
443     internal bool IsExportingWebPart { get; }
444     internal bool IsExportingWebPartShared { get; }
445     internal bool IsInAspCompatMode { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
446     internal bool IsInOnFormRender { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
447     internal bool IsPartialRenderingSupported { get; }
448     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
449     public bool IsPostBack { get; }
450     public bool IsPostBackEventControlRegistered { get; }
451     [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
452     public bool IsReusable { get; }
453     internal bool IsTransacted { get; }
454     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
455     public bool IsValid { get; }
456     [Browsable(false)]
457     public IDictionary Items { get; }
458     internal string LastFocusedControl { [AspNetHostingPermission(SecurityAction.Assert, Level=AspNetHostingPermissionLevel.Low)] get; }
459     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
460     public int LCID { get; set; }
461     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
462     public bool MaintainScrollPositionOnPostBack { get; set; }
463     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), WebSysDescription("MasterPage_MasterPage"), Browsable(false)]
464     public MasterPage Master { get; }
465     [WebSysDescription("MasterPage_MasterPageFile"), DefaultValue(""), WebCategory("Behavior")]
466     public virtual string MasterPageFile { get; set; }
467     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
468     public int MaxPageStateFieldLength { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
469     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Bindable(true), Localizable(true)]
470     public string MetaDescription { get; set; }
471     [Localizable(true), Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
472     public string MetaKeywords { get; set; }
473     public ModelBindingExecutionContext ModelBindingExecutionContext { get; }
474     public ModelStateDictionary ModelState { get; }
475     public PageAdapter PageAdapter { get; }
476     protected virtual PageStatePersister PageStatePersister { get; }
477     internal Stack PartialCachingControlStack { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
478     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
479     public Page PreviousPage { get; }
480     internal string RelativeFilePath { get; }
481     private bool RenderDisabledControlsScript { get; }
482     internal bool RenderFocusScript { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
483     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
484     public HttpRequest Request { [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] get; }
485     internal HttpRequest RequestInternal { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
486     internal NameValueCollection RequestValueCollection { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
487     internal string RequestViewStateString { get; }
488     internal bool RequiresViewStateEncryptionInternal { get; }
489     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
490     public HttpResponse Response { get; }
491     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
492     public string ResponseEncoding { get; set; }
493     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
494     public RouteData RouteData { get; }
495     internal IScriptManager ScriptManager { get; }
496     internal Type ScriptManagerType { get; set; }
497     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
498     public HttpServerUtility Server { get; }
499     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
500     public virtual HttpSessionState Session { get; }
501     [EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(false)]
502     public bool SkipFormActionValidation { get; set; }
503     [Filterable(false), Browsable(false), Obsolete("The recommended alternative is Page.SetFocus and Page.MaintainScrollPositionOnPostBack. http://go.microsoft.com/fwlink/?linkid=14202")]
504     public bool SmartNavigation { get; set; }
505     [Filterable(false), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
506     public virtual string StyleSheetTheme { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
507     internal bool SupportsStyleSheets { get; }
508     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
509     public virtual string Theme { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
510     [Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(true)]
511     public string Title { get; set; }
512     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
513     public TraceContext Trace { get; }
514     [EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
515     public bool TraceEnabled { get; set; }
516     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
517     public TraceMode TraceModeValue { get; set; }
518     [EditorBrowsable(EditorBrowsableState.Never)]
519     protected int TransactionMode { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] set; }
520     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Advanced), Browsable(false)]
521     public string UICulture { get; set; }
522     protected internal virtual string UniqueFilePathSuffix { get; }
523     [WebSysDescription("Page_UnobtrusiveValidationMode"), DefaultValue(0), WebCategory("Behavior")]
524     public UnobtrusiveValidationMode UnobtrusiveValidationMode { get; set; }
525     [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
526     public IPrincipal User { get; }
527     [EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DefaultValue(2)]
528     public override ValidateRequestMode ValidateRequestMode { get; set; }
529     internal string ValidatorInvalidControl { get; }
530     [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
531     public ValidatorCollection Validators { get; }
532     [Browsable(false), DefaultValue(0), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
533     public ViewStateEncryptionMode ViewStateEncryptionMode { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
534     [Browsable(false)]
535     public string ViewStateUserKey { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; }
536     [Browsable(false)]
537     public override bool Visible { [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")] get; set; }
538     internal XhtmlConformanceMode XhtmlConformanceMode { get; }
539 
540     // Nested Types
541     [CompilerGenerated]
542     private struct <PerformPreInitAsync>d__c : IAsyncStateMachine
543     {
544         // Fields
545         public int <>1__state;
546         public Page <>4__this;
547         public IDisposable <>7__wrapd;
548         public AsyncTaskMethodBuilder <>t__builder;
549         private object <>t__stack;
550         private WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter <>u__$awaitere;
551 
552         // Methods
553         private void MoveNext();
554         [DebuggerHidden]
555         private void SetStateMachine(IAsyncStateMachine param0);
556     }
557 
558     [CompilerGenerated]
559     private struct <PrepareCallbackAsync>d__1f : IAsyncStateMachine
560     {
561         // Fields
562         public int <>1__state;
563         public Page <>4__this;
564         public IDisposable <>7__wrap21;
565         public AsyncTaskMethodBuilder <>t__builder;
566         private object <>t__stack;
567         private WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter <>u__$awaiter22;
568         public string <param>5__20;
569         public string callbackControlID;
570 
571         // Methods
572         private void MoveNext();
573         [DebuggerHidden]
574         private void SetStateMachine(IAsyncStateMachine param0);
575     }
576 
577     [CompilerGenerated]
578     private struct <ProcessRequestAsync>d__10 : IAsyncStateMachine
579     {
580         // Fields
581         public int <>1__state;
582         public Page <>4__this;
583         public AsyncTaskMethodBuilder <>t__builder;
584         private object <>t__stack;
585         private WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter <>u__$awaiter12;
586         public bool <needToCallEndTrace>5__11;
587         public bool includeStagesAfterAsyncPoint;
588         public bool includeStagesBeforeAsyncPoint;
589 
590         // Methods
591         private void MoveNext();
592         [DebuggerHidden]
593         private void SetStateMachine(IAsyncStateMachine param0);
594     }
595 
596     [CompilerGenerated]
597     private struct <ProcessRequestAsync>d__2c : IAsyncStateMachine
598     {
599         // Fields
600         public int <>1__state;
601         public Page <>4__this;
602         public AsyncTaskMethodBuilder <>t__builder;
603         private object <>t__stack;
604         private TaskAwaiter <>u__$awaiter2f;
605         public CancellationToken <cancellationToken>5__2e;
606         public CancellationTokenSource <cancellationTokenSource>5__2d;
607         public HttpContext context;
608         public Page.<>c__DisplayClass2a CS$<>8__locals2b;
609 
610         // Methods
611         private void MoveNext();
612         [DebuggerHidden]
613         private void SetStateMachine(IAsyncStateMachine param0);
614     }
615 
616     [CompilerGenerated]
617     private struct <ProcessRequestMainAsync>d__14 : IAsyncStateMachine
618     {
619         // Fields
620         public int <>1__state;
621         public Page <>4__this;
622         public IDisposable <>7__wrap1a;
623         public IDisposable <>7__wrap1b;
624         public IDisposable <>7__wrap1c;
625         public IDisposable <>7__wrap1d;
626         public AsyncTaskMethodBuilder <>t__builder;
627         private object <>t__stack;
628         private WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter <>u__$awaiter19;
629         public string <callbackControlId>5__17;
630         public HttpContext <con>5__15;
631         public string <exportedWebPartID>5__16;
632         public Task <initRecursiveTask>5__18;
633         public bool includeStagesAfterAsyncPoint;
634         public bool includeStagesBeforeAsyncPoint;
635 
636         // Methods
637         private void MoveNext();
638         [DebuggerHidden]
639         private void SetStateMachine(IAsyncStateMachine param0);
640     }
641 
642     [CompilerGenerated]
643     private struct <RaiseChangedEventsAsync>d__5 : IAsyncStateMachine
644     {
645         // Fields
646         public int <>1__state;
647         public Page <>4__this;
648         public IDisposable <>7__wrap9;
649         public AsyncTaskMethodBuilder <>t__builder;
650         private object <>t__stack;
651         private WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter <>u__$awaitera;
652         public Control <c>5__7;
653         public IPostBackDataHandler <changedPostDataConsumer>5__8;
654         public int <i>5__6;
655 
656         // Methods
657         private void MoveNext();
658         [DebuggerHidden]
659         private void SetStateMachine(IAsyncStateMachine param0);
660     }
661 
662     private class LegacyPageAsyncInfo
663     {
664         // Fields
665         private HttpApplication _app;
666         private bool _asyncPointReached;
667         private HttpAsyncResult _asyncResult;
668         private ArrayList _beginHandlers;
669         private bool _callerIsBlocking;
670         private WaitCallback _callHandlersThreadpoolCallback;
671         private bool _completed;
672         private AsyncCallback _completionCallback;
673         private int _currentHandler;
674         private ArrayList _endHandlers;
675         private Exception _error;
676         private int _handlerCount;
677         private Page _page;
678         private ArrayList _stateObjects;
679         private AspNetSynchronizationContextBase _syncContext;
680 
681         // Methods
682         internal LegacyPageAsyncInfo(Page page);
683         internal void AddHandler(BeginEventHandler beginHandler, EndEventHandler endHandler, object state);
684         internal void CallHandlers(bool onPageThread);
685         private void CallHandlersFromThreadpoolThread(object data);
686         private void CallHandlersPossiblyUnderLock(bool onPageThread);
687         private void OnAsyncHandlerCompletion(IAsyncResult ar);
688         internal void SetError(Exception error);
689 
690         // Properties
691         internal bool AsyncPointReached { get; set; }
692         internal HttpAsyncResult AsyncResult { get; set; }
693         internal bool CallerIsBlocking { get; set; }
694     }
695 }
696 
697  
698 Expand Methods
699  
View Code

内容好多啊,这也就是为什么我们在后台类中可以访问Response,Request,Server等属性的原因了。看下这个类的ProcessRequest

 1 [EditorBrowsable(EditorBrowsableState.Never)]
 2 public virtual void ProcessRequest(HttpContext context)
 3 {
 4     if ((HttpRuntime.NamedPermissionSet != null) && !HttpRuntime.DisableProcessRequestInApplicationTrust)
 5     {
 6         if (!HttpRuntime.ProcessRequestInApplicationTrust)
 7         {
 8             this.ProcessRequestWithAssert(context);
 9             return;
10         }
11         if (base.NoCompile)
12         {
13             HttpRuntime.NamedPermissionSet.PermitOnly();
14         }
15     }
16     this.ProcessRequestWithNoAssert(context);
17 }
18 
19  
20 
21  
View Code

进入---》this.ProcessRequestWithAssert(context);---》this.ProcessRequestWithNoAssert(context);---》this.ProcessRequest();---》this.ProcessRequest(true, true);仔细看下最后这个方法this.ProcessRequest(true, true);

 1 private void ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint)
 2 {
 3     if (includeStagesBeforeAsyncPoint)
 4     {
 5         this.FrameworkInitialize();
 6         base.ControlState = ControlState.FrameworkInitialized;
 7     }
 8     bool flag = this.Context.WorkerRequest is IIS7WorkerRequest;
 9     try
10     {
11         try
12         {
13             if (this.IsTransacted)
14             {
15                 this.ProcessRequestTransacted();
16             }
17             else
18             {
19                 this.ProcessRequestMain(includeStagesBeforeAsyncPoint, includeStagesAfterAsyncPoint);
20             }
21             if (includeStagesAfterAsyncPoint)
22             {
23                 flag = false;
24                 this.ProcessRequestEndTrace();
25             }
26         }
27         catch (ThreadAbortException)
28         {
29             try
30             {
31                 if (flag)
32                 {
33                     this.ProcessRequestEndTrace();
34                 }
35             }
36             catch
37             {
38             }
39         }
40         finally
41         {
42             if (includeStagesAfterAsyncPoint)
43             {
44                 this.ProcessRequestCleanup();
45             }
46         }
47     }
48     catch
49     {
50         throw;
51     }
52 }
53 
54  
55 
56  
View Code
注意一下this.FrameworkInitialize();这个FramworkInitiallize在Page类中是虚方法,而在页面类中重写了这个方法,其实通过this调用,也说明了这里这个方法是调用前台页面类的方法。看下前台页面类的FramworkInitialize方法。
1 [DebuggerNonUserCode]
2 protected override void FrameworkInitialize()
3 {
4     base.FrameworkInitialize();
5     this.__BuildControlTree(this);
6     base.AddWrappedFileDependencies(__fileDependencies);
7     base.Request.ValidateInput();
8 }
View Code

 先调用了父类的FrameworkInitialize方法,我们主要看这句调用this.__BuildControlTree(this);从表面上我们可以看出是构建控件树,参数this,也就是将当前页面类对象当做参数传进去,我们进入到这个方法内部查看

 1 [DebuggerNonUserCode]
 2 private void __BuildControlTree(demo_aspx __ctrl)
 3 {
 4     this.InitializeCulture();
 5     LiteralControl __ctrl1 = this.__BuildControl__control2();
 6     IParserAccessor __parser = __ctrl;
 7     __parser.AddParsedSubObject(__ctrl1);
 8     HtmlHead __ctrl2 = this.__BuildControl__control3();
 9     __parser.AddParsedSubObject(__ctrl2);
10     LiteralControl __ctrl3 = this.__BuildControl__control6();
11     __parser.AddParsedSubObject(__ctrl3);
12     HtmlForm __ctrl4 = this.__BuildControlform1();
13     __parser.AddParsedSubObject(__ctrl4);
14     LiteralControl __ctrl5 = this.__BuildControl__control7();
15     __parser.AddParsedSubObject(__ctrl5);
16 }
View Code

 注意,这里生成的内容是根据前台页面服务器端控件生成的,也就是说前台页面中包含的内容不同,这里生成的代码也会不同。控件越多,代码也会越多。我们只分析一部分,其实后面都是一样的原理。

LiteralControl __ctrl1 = this.__BuildControl__control2();我们看这句,查看一下this.__BuildControl__control2();注意,这是前台类中的一个方法
 1 [DebuggerNonUserCode]
 2 private LiteralControl __BuildControl__control2()
 3 {
 4     LiteralControl __ctrl = new LiteralControl("\r\n\r\n<!DOCTYPE html>\r\n\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n");
 5     object[] CS$0$0001 = new object[5];
 6     CS$0$0001[0] = __ctrl;
 7     CS$0$0001[2] = 0x67;
 8     CS$0$0001[3] = 0x44;
 9     CS$0$0001[4] = true;
10     this.__PageInspector_SetTraceData(CS$0$0001);
11     return __ctrl;
12 }
13 
14  
View Code

 

可以与前台页面的html代码对照一下

ASP.NET 运行机制续(完结)_第5张图片

LiteralControl这个控件类就是封装字符串的,在asp.net看来,只要不是c#代码及服务端控件,都是字符串。例如后面的<input type="text" id="TextBox3" />

将这个控件对象(_ctrl)返回。继续看下一句,IParserAccessor __parser = __ctrl;注意__ctrl变量是当前的前台页面类对象,而我们可以向当前页面类对象的父类查找(),最终可以看到前台页面类继承自Control

ASP.NET 运行机制续(完结)_第6张图片

这样就清晰多了吧。我们继续看__parser.AddParsedSubObject(__ctrl1);这是将上面的一个方法返回的字符串对象放入当前页面类对象控件集合中去,HtmlHead __ctrl2 = this.__BuildControl__control3();看这个this.__BuildControl__control3();方法,
 1 [DebuggerNonUserCode]
 2 private HtmlHead __BuildControl__control3()
 3 {
 4     HtmlHead __ctrl = new HtmlHead("head");
 5     HtmlMeta __ctrl1 = this.__BuildControl__control4();
 6     IParserAccessor __parser = __ctrl;
 7     __parser.AddParsedSubObject(__ctrl1);
 8     HtmlTitle __ctrl2 = this.__BuildControl__control5();
 9     __parser.AddParsedSubObject(__ctrl2);
10     object[] CS$0$0001 = new object[5];
11     CS$0$0001[0] = __ctrl;
12     CS$0$0001[2] = 0xab;
13     CS$0$0001[3] = 0x79;
14     CS$0$0001[4] = false;
15     this.__PageInspector_SetTraceData(CS$0$0001);
16     return __ctrl;
17 }
18 
19  
View Code

 


因为前台页面html中<head runat="server">所以后台将这个看做是服务器端控件,为他生成了一个HtmlHead __ctrl = new HtmlHead("head");对象,HtmlMeta __ctrl1 = this.__BuildControl__control4();继续看this.__BuildControl__control4();
 1 [DebuggerNonUserCode]
 2 private HtmlMeta __BuildControl__control4()
 3 {
 4     HtmlMeta __ctrl = new HtmlMeta();
 5     ((IAttributeAccessor) __ctrl).SetAttribute("http-equiv", "Content-Type");
 6     __ctrl.Content = "text/html; charset=utf-8";
 7     object[] CS$0$0001 = new object[5];
 8     CS$0$0001[0] = __ctrl;
 9     CS$0$0001[2] = 0xc2;
10     CS$0$0001[3] = 0x44;
11     CS$0$0001[4] = false;
12     this.__PageInspector_SetTraceData(CS$0$0001);
13     return __ctrl;
14 }
15 
16  
View Code
继续以结合前台html代码方式查看

ASP.NET 运行机制续(完结)_第7张图片

这里面是循环嵌套的,难道是不难,只是有些绕。继续贴图

ASP.NET 运行机制续(完结)_第8张图片

图没有全画出来,但意思表达出来了,就是这样,到这里整个一颗控件树就创建出来了。下面我们再返回上面说到的this.ProcessRequest(true, true);这个方法内部,进入this.ProcessRequestMain(includeStagesBeforeAsyncPoint, includeStagesAfterAsyncPoint);方法

  1 private void ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint)
  2 {
  3     try
  4     {
  5         HttpContext context = this.Context;
  6         string str = null;
  7         if (includeStagesBeforeAsyncPoint)
  8         {
  9             if (this.IsInAspCompatMode)
 10             {
 11                 AspCompatApplicationStep.OnPageStartSessionObjects();
 12             }
 13             if (this.PageAdapter != null)
 14             {
 15                 this._requestValueCollection = this.PageAdapter.DeterminePostBackMode();
 16                 if (this._requestValueCollection != null)
 17                 {
 18                     this._unvalidatedRequestValueCollection = this.PageAdapter.DeterminePostBackModeUnvalidated();
 19                 }
 20             }
 21             else
 22             {
 23                 this._requestValueCollection = this.DeterminePostBackMode();
 24                 if (this._requestValueCollection != null)
 25                 {
 26                     this._unvalidatedRequestValueCollection = this.DeterminePostBackModeUnvalidated();
 27                 }
 28             }
 29             string callbackControlID = string.Empty;
 30             if (this.DetermineIsExportingWebPart())
 31             {
 32                 if (!RuntimeConfig.GetAppConfig().WebParts.EnableExport)
 33                 {
 34                     throw new InvalidOperationException(SR.GetString("WebPartExportHandler_DisabledExportHandler"));
 35                 }
 36                 str = this.Request.QueryString["webPart"];
 37                 if (string.IsNullOrEmpty(str))
 38                 {
 39                     throw new InvalidOperationException(SR.GetString("WebPartExportHandler_InvalidArgument"));
 40                 }
 41                 if (string.Equals(this.Request.QueryString["scope"], "shared", StringComparison.OrdinalIgnoreCase))
 42                 {
 43                     this._pageFlags.Set(4);
 44                 }
 45                 string str3 = this.Request.QueryString["query"];
 46                 if (str3 == null)
 47                 {
 48                     str3 = string.Empty;
 49                 }
 50                 this.Request.QueryStringText = str3;
 51                 context.Trace.IsEnabled = false;
 52             }
 53             if (this._requestValueCollection != null)
 54             {
 55                 if (this._requestValueCollection["__VIEWSTATEENCRYPTED"] != null)
 56                 {
 57                     this.ContainsEncryptedViewState = true;
 58                 }
 59                 callbackControlID = this._requestValueCollection["__CALLBACKID"];
 60                 if ((callbackControlID != null) && (this._request.HttpVerb == HttpVerb.POST))
 61                 {
 62                     this._isCallback = true;
 63                 }
 64                 else if (!this.IsCrossPagePostBack)
 65                 {
 66                     VirtualPath path = null;
 67                     if (this._requestValueCollection["__PREVIOUSPAGE"] != null)
 68                     {
 69                         try
 70                         {
 71                             path = VirtualPath.CreateNonRelativeAllowNull(DecryptString(this._requestValueCollection["__PREVIOUSPAGE"], Purpose.WebForms_Page_PreviousPageID));
 72                         }
 73                         catch
 74                         {
 75                             this._pageFlags[8] = true;
 76                         }
 77                         if ((path != null) && (path != this.Request.CurrentExecutionFilePathObject))
 78                         {
 79                             this._pageFlags[8] = true;
 80                             this._previousPagePath = path;
 81                         }
 82                     }
 83                 }
 84             }
 85             if (this.MaintainScrollPositionOnPostBack)
 86             {
 87                 this.LoadScrollPosition();
 88             }
 89             if (context.TraceIsEnabled)
 90             {
 91                 this.Trace.Write("aspx.page", "Begin PreInit");
 92             }
 93             if (EtwTrace.IsTraceEnabled(5, 4))
 94             {
 95                 EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_INIT_ENTER, this._context.WorkerRequest);
 96             }
 97             this.PerformPreInit();
 98             if (EtwTrace.IsTraceEnabled(5, 4))
 99             {
100                 EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_INIT_LEAVE, this._context.WorkerRequest);
101             }
102             if (context.TraceIsEnabled)
103             {
104                 this.Trace.Write("aspx.page", "End PreInit");
105             }
106             if (context.TraceIsEnabled)
107             {
108                 this.Trace.Write("aspx.page", "Begin Init");
109             }
110             if (EtwTrace.IsTraceEnabled(5, 4))
111             {
112                 EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_INIT_ENTER, this._context.WorkerRequest);
113             }
114             this.InitRecursive(null);
115             if (EtwTrace.IsTraceEnabled(5, 4))
116             {
117                 EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_INIT_LEAVE, this._context.WorkerRequest);
118             }
119             if (context.TraceIsEnabled)
120             {
121                 this.Trace.Write("aspx.page", "End Init");
122             }
123             if (context.TraceIsEnabled)
124             {
125                 this.Trace.Write("aspx.page", "Begin InitComplete");
126             }
127             this.OnInitComplete(EventArgs.Empty);
128             if (context.TraceIsEnabled)
129             {
130                 this.Trace.Write("aspx.page", "End InitComplete");
131             }
132             if (this.IsPostBack)
133             {
134                 if (context.TraceIsEnabled)
135                 {
136                     this.Trace.Write("aspx.page", "Begin LoadState");
137                 }
138                 if (EtwTrace.IsTraceEnabled(5, 4))
139                 {
140                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_VIEWSTATE_ENTER, this._context.WorkerRequest);
141                 }
142                 this.LoadAllState();
143                 if (EtwTrace.IsTraceEnabled(5, 4))
144                 {
145                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_VIEWSTATE_LEAVE, this._context.WorkerRequest);
146                 }
147                 if (context.TraceIsEnabled)
148                 {
149                     this.Trace.Write("aspx.page", "End LoadState");
150                     this.Trace.Write("aspx.page", "Begin ProcessPostData");
151                 }
152                 if (EtwTrace.IsTraceEnabled(5, 4))
153                 {
154                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_POSTDATA_ENTER, this._context.WorkerRequest);
155                 }
156                 this.ProcessPostData(this._requestValueCollection, true);
157                 if (EtwTrace.IsTraceEnabled(5, 4))
158                 {
159                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_POSTDATA_LEAVE, this._context.WorkerRequest);
160                 }
161                 if (context.TraceIsEnabled)
162                 {
163                     this.Trace.Write("aspx.page", "End ProcessPostData");
164                 }
165             }
166             if (context.TraceIsEnabled)
167             {
168                 this.Trace.Write("aspx.page", "Begin PreLoad");
169             }
170             this.OnPreLoad(EventArgs.Empty);
171             if (context.TraceIsEnabled)
172             {
173                 this.Trace.Write("aspx.page", "End PreLoad");
174             }
175             if (context.TraceIsEnabled)
176             {
177                 this.Trace.Write("aspx.page", "Begin Load");
178             }
179             if (EtwTrace.IsTraceEnabled(5, 4))
180             {
181                 EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_ENTER, this._context.WorkerRequest);
182             }
183             this.LoadRecursive();
184             if (EtwTrace.IsTraceEnabled(5, 4))
185             {
186                 EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_LEAVE, this._context.WorkerRequest);
187             }
188             if (context.TraceIsEnabled)
189             {
190                 this.Trace.Write("aspx.page", "End Load");
191             }
192             if (this.IsPostBack)
193             {
194                 if (context.TraceIsEnabled)
195                 {
196                     this.Trace.Write("aspx.page", "Begin ProcessPostData Second Try");
197                 }
198                 this.ProcessPostData(this._leftoverPostData, false);
199                 if (context.TraceIsEnabled)
200                 {
201                     this.Trace.Write("aspx.page", "End ProcessPostData Second Try");
202                     this.Trace.Write("aspx.page", "Begin Raise ChangedEvents");
203                 }
204                 if (EtwTrace.IsTraceEnabled(5, 4))
205                 {
206                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_POST_DATA_CHANGED_ENTER, this._context.WorkerRequest);
207                 }
208                 this.RaiseChangedEvents();
209                 if (EtwTrace.IsTraceEnabled(5, 4))
210                 {
211                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_POST_DATA_CHANGED_LEAVE, this._context.WorkerRequest);
212                 }
213                 if (context.TraceIsEnabled)
214                 {
215                     this.Trace.Write("aspx.page", "End Raise ChangedEvents");
216                     this.Trace.Write("aspx.page", "Begin Raise PostBackEvent");
217                 }
218                 if (EtwTrace.IsTraceEnabled(5, 4))
219                 {
220                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RAISE_POSTBACK_ENTER, this._context.WorkerRequest);
221                 }
222                 this.RaisePostBackEvent(this._requestValueCollection);
223                 if (EtwTrace.IsTraceEnabled(5, 4))
224                 {
225                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RAISE_POSTBACK_LEAVE, this._context.WorkerRequest);
226                 }
227                 if (context.TraceIsEnabled)
228                 {
229                     this.Trace.Write("aspx.page", "End Raise PostBackEvent");
230                 }
231             }
232             if (context.TraceIsEnabled)
233             {
234                 this.Trace.Write("aspx.page", "Begin LoadComplete");
235             }
236             this.OnLoadComplete(EventArgs.Empty);
237             if (context.TraceIsEnabled)
238             {
239                 this.Trace.Write("aspx.page", "End LoadComplete");
240             }
241             if (this.IsPostBack && this.IsCallback)
242             {
243                 this.PrepareCallback(callbackControlID);
244             }
245             else if (!this.IsCrossPagePostBack)
246             {
247                 if (context.TraceIsEnabled)
248                 {
249                     this.Trace.Write("aspx.page", "Begin PreRender");
250                 }
251                 if (EtwTrace.IsTraceEnabled(5, 4))
252                 {
253                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_RENDER_ENTER, this._context.WorkerRequest);
254                 }
255                 this.PreRenderRecursiveInternal();
256                 if (EtwTrace.IsTraceEnabled(5, 4))
257                 {
258                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_RENDER_LEAVE, this._context.WorkerRequest);
259                 }
260                 if (context.TraceIsEnabled)
261                 {
262                     this.Trace.Write("aspx.page", "End PreRender");
263                 }
264             }
265         }
266         if ((this._legacyAsyncInfo == null) || this._legacyAsyncInfo.CallerIsBlocking)
267         {
268             this.ExecuteRegisteredAsyncTasks();
269         }
270         this.ValidateRawUrlIfRequired();
271         if (includeStagesAfterAsyncPoint)
272         {
273             if (this.IsCallback)
274             {
275                 this.RenderCallback();
276             }
277             else if (!this.IsCrossPagePostBack)
278             {
279                 if (context.TraceIsEnabled)
280                 {
281                     this.Trace.Write("aspx.page", "Begin PreRenderComplete");
282                 }
283                 this.PerformPreRenderComplete();
284                 if (context.TraceIsEnabled)
285                 {
286                     this.Trace.Write("aspx.page", "End PreRenderComplete");
287                 }
288                 if (context.TraceIsEnabled)
289                 {
290                     this.BuildPageProfileTree(this.EnableViewState);
291                     this.Trace.Write("aspx.page", "Begin SaveState");
292                 }
293                 if (EtwTrace.IsTraceEnabled(5, 4))
294                 {
295                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_SAVE_VIEWSTATE_ENTER, this._context.WorkerRequest);
296                 }
297                 this.SaveAllState();
298                 if (EtwTrace.IsTraceEnabled(5, 4))
299                 {
300                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_SAVE_VIEWSTATE_LEAVE, this._context.WorkerRequest);
301                 }
302                 if (context.TraceIsEnabled)
303                 {
304                     this.Trace.Write("aspx.page", "End SaveState");
305                     this.Trace.Write("aspx.page", "Begin SaveStateComplete");
306                 }
307                 this.OnSaveStateComplete(EventArgs.Empty);
308                 if (context.TraceIsEnabled)
309                 {
310                     this.Trace.Write("aspx.page", "End SaveStateComplete");
311                     this.Trace.Write("aspx.page", "Begin Render");
312                 }
313                 if (EtwTrace.IsTraceEnabled(5, 4))
314                 {
315                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RENDER_ENTER, this._context.WorkerRequest);
316                 }
317                 if (str != null)
318                 {
319                     this.ExportWebPart(str);
320                 }
321                 else
322                 {
323                     this.RenderControl(this.CreateHtmlTextWriter(this.Response.Output));
324                 }
325                 if (EtwTrace.IsTraceEnabled(5, 4))
326                 {
327                     EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RENDER_LEAVE, this._context.WorkerRequest);
328                 }
329                 if (context.TraceIsEnabled)
330                 {
331                     this.Trace.Write("aspx.page", "End Render");
332                 }
333                 this.CheckRemainingAsyncTasks(false);
334             }
335         }
336     }
337     catch (ThreadAbortException exception)
338     {
339         HttpApplication.CancelModuleException exceptionState = exception.ExceptionState as HttpApplication.CancelModuleException;
340         if (((!includeStagesBeforeAsyncPoint || !includeStagesAfterAsyncPoint) || ((this._context.Handler != this) || (this._context.ApplicationInstance == null))) || ((exceptionState == null) || exceptionState.Timeout))
341         {
342             this.CheckRemainingAsyncTasks(true);
343             throw;
344         }
345         this._context.ApplicationInstance.CompleteRequest();
346         ThreadResetAbortWithAssert();
347     }
348     catch (ConfigurationException)
349     {
350         throw;
351     }
352     catch (Exception exception3)
353     {
354         PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_DURING_REQUEST);
355         PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_TOTAL);
356         if (!this.HandleError(exception3))
357         {
358             throw;
359         }
360     }
361 }
362 
363  
364 
365  
View Code

 

内容还是比较多的,但是我们着重依次看几个方法。
1.this.LoadAllState();将表单隐藏域__VIEWSTATE里的数据设置到页面对象ViewState属性
2.this.ProcessPostData(this._requestValueCollection, true);这个与第四个类似,但也有不同。将表单里提交的控件数据设置给页面对象的控件树中对应的控件。要知道这时候前台页面类对象的控件树已经构建完毕了。所以通过这个方法将表单提交的数据封装到控件树上。例如,前台页面<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>文本框中添加test字符串,点击提交的时候,我们在后台类中可以根据TextBox1.Text方式可以获取到这个文本框中的数据(test)。
3.this.LoadRecursive();调用我们在后台的Page_Load中编写的代码,此时我们可以在后台类中访问到浏览器提交的表单控件值了
4.this.ProcessPostData(this._leftoverPostData,false);为在Page_Load中添加的心控件赋值(值来自表单提交),我们可以在Page_Load方法中使用
TextBox txt = new TextBox(); txt.ID = "test"; this.form1.Controls.Add(txt);同样可以讲文本框添加到前台页面中去,注意第二个方法中也是将数据封装到控件树,只是一个前后顺序的问题,也是就说在第二个方法(this.ProcessPostData(this._requestValueCollection, true);)封装控件树数据时有些在Page_Load方法中添加的控件(TextBox txt = new TextBox(); txt.ID = "test"; this.form1.Controls.Add(txt);)这时并没有在控件树中,所以数据没办法在第二个方法中封装。这时第四个方法就起作用了。
5.this.RaiseChangeEnvents();执行控件非点击回传事件,例如页面中的DropDownlist
6.this.RaisePostBackEvent(this._requsetValueCollection);执行控件点击回传事件,例如Button
7.this.SaveAllState();将控件的属性状态存入页面的ViewState中
8.this.RenderControl(this.CreatHtmlTextWriter(this.Response.Output));递归调用控件树里的每个控件的Render来生成整个页面的html代码
而在这里也可以解释为什么Page_Load中写Response.Write("测试Page_Load方法中使用Response.Write方法输出");会输出到页面<html>标签前面。因为Response.Write并不是马上输出到浏览器,而是有个缓存区,全部处理完毕,在this.RenderControl才会输出,而html一些代码在
this.RenderControl中才会放入缓冲区。前后顺序的问题。
上面忘记提到为什么后台类可以访问前台页面类对象了,我们都知道子类可以访问父类的非私有成员,但是前台类才是子类,为什么父类可以访问子类的东西呢?我们反编译后台类看下
 1 public class Demo : Page
 2 {
 3     // Fields
 4     protected HtmlForm form1;
 5     protected TextBox TextBox1;
 6     protected HtmlInputText TextBox2;
 7 
 8     // Methods
 9     public Demo();
10     protected void Page_Load(object sender, EventArgs e);
11 }
12 
13  
14 Expand Methods
15  
View Code

 原来后台类也声明了前台类的属性,这是在编译的时候实现的,而我们在编写的时候可以智能提示出来那就要归结vs的强大了。那就要有人问了,这里只进行了声明,并没有赋值,那我们返回看我们前台页面类构造控件树那里,查看我们前台给了服务器端控件ID属性的控件<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 我们看这个控件被构建的过程

 1 [DebuggerNonUserCode]
 2 private TextBox __BuildControlTextBox1()
 3 {
 4     TextBox __ctrl = new TextBox();
 5     base.TextBox1 = __ctrl;
 6     __ctrl.ApplyStyleSheetSkin(this);
 7     __ctrl.ID = "TextBox1";
 8     object[] CS$0$0001 = new object[5];
 9     CS$0$0001[0] = __ctrl;
10     CS$0$0001[2] = 0x1ac;
11     CS$0$0001[3] = 0x38;
12     CS$0$0001[4] = false;
13     this.__PageInspector_SetTraceData(CS$0$0001);
14     return __ctrl;
15 }
View Code

  是不是看到了前台类属性赋给后台类属性了呢?

 这节内容有些多,又考虑到每个人生成的前台页面类可能不同,虽然内容很简单,但还是将源码上传,这样方便对照。

ReflectorWeb.rar源码

 

你可能感兴趣的:(asp.net)