asp.net的事件机制问题
学了一段时间的asp.net,一直对这个事件机制困扰。就我知道的asp.net管道模型(通过看Reflector)
是先走 public int ProcessRequest(IntPtr ecb, int iWRType)方法
然后创建WorkRequest对象,把请求数据传到wr实例中
再调用ProcessRequestInternal方法,
这里面创建了context对象(通过wr)
和HttpApplicationFactory.GetApplicationInstance(context)创建HttpApplication实例
然后就调用HttpApplication的ProcessRequest方法。
然后就看不到了
msdn上说走22个步骤,19个方法,但是我没有找到这些事件在哪,也不知道它们如何被触发希望有人能给我解惑一下。 asp.net事件 ASP.NET --------------------编程问答--------------------
// System.Web.UI.Page--------------------编程问答-------------------- “管道模型”哪里有具体内容呢?你只看抽象,不看具像,这就好像是“永不落地”的飞机啊。 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 你是要学开车呢,还是去设计汽车,学开车,不一定要去学如何设计汽车,会用就好,原理不用管 --------------------编程问答--------------------
private void ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint)
{
try
{
HttpContext context = this.Context;
string text = null;
if (includeStagesBeforeAsyncPoint)
{
if (this.IsInAspCompatMode)
{
AspCompatApplicationStep.OnPageStartSessionObjects();
}
if (this.PageAdapter != null)
{
this._requestValueCollection = this.PageAdapter.DeterminePostBackMode();
}
else
{
this._requestValueCollection = this.DeterminePostBackMode();
}
string text2 = string.Empty;
if (this.DetermineIsExportingWebPart())
{
if (!RuntimeConfig.GetAppConfig().WebParts.EnableExport)
{
throw new InvalidOperationException(SR.GetString("WebPartExportHandler_DisabledExportHandler"));
}
text = this.Request.QueryString["webPart"];
if (string.IsNullOrEmpty(text))
{
throw new InvalidOperationException(SR.GetString("WebPartExportHandler_InvalidArgument"));
}
if (string.Equals(this.Request.QueryString["scope"], "shared", StringComparison.OrdinalIgnoreCase))
{
this._pageFlags.Set(4);
}
string text3 = this.Request.QueryString["query"];
if (text3 == null)
{
text3 = string.Empty;
}
this.Request.QueryStringText = text3;
context.Trace.IsEnabled = false;
}
if (this._requestValueCollection != null)
{
if (this._requestValueCollection["__VIEWSTATEENCRYPTED"] != null)
{
this.ContainsEncryptedViewState = true;
}
text2 = this._requestValueCollection["__CALLBACKID"];
if (text2 != null && this._request.HttpVerb == HttpVerb.POST)
{
this._isCallback = true;
}
else
{
if (!this.IsCrossPagePostBack)
{
VirtualPath virtualPath = null;
if (this._requestValueCollection["__PREVIOUSPAGE"] != null)
{
try
{
virtualPath = VirtualPath.CreateNonRelativeAllowNull(Page.DecryptString(this._requestValueCollection["__PREVIOUSPAGE"]));
}
catch
{
this._pageFlags[8] = true;
}
if (virtualPath != null && virtualPath != this.Request.CurrentExecutionFilePathObject)
{
this._pageFlags[8] = true;
this._previousPagePath = virtualPath;
}
}
}
}
}
if (this.MaintainScrollPositionOnPostBack)
{
this.LoadScrollPosition();
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin PreInit");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_INIT_ENTER, this._context.WorkerRequest);
}
this.PerformPreInit();
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_INIT_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End PreInit");
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin Init");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_INIT_ENTER, this._context.WorkerRequest);
}
this.InitRecursive(null);
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_INIT_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End Init");
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin InitComplete");
}
this.OnInitComplete(EventArgs.Empty);
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End InitComplete");
}
if (this.IsPostBack)
{
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin LoadState");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_VIEWSTATE_ENTER, this._context.WorkerRequest);
}
this.LoadAllState();
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_VIEWSTATE_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End LoadState");
this.Trace.Write("aspx.page", "Begin ProcessPostData");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_POSTDATA_ENTER, this._context.WorkerRequest);
}
this.ProcessPostData(this._requestValueCollection, true);
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_POSTDATA_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End ProcessPostData");
}
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin PreLoad");
}
this.OnPreLoad(EventArgs.Empty);
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End PreLoad");
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin Load");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_ENTER, this._context.WorkerRequest);
}
this.LoadRecursive();
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_LOAD_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End Load");
}
if (this.IsPostBack)
{
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin ProcessPostData Second Try");
}
this.ProcessPostData(this._leftoverPostData, false);
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End ProcessPostData Second Try");
this.Trace.Write("aspx.page", "Begin Raise ChangedEvents");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_POST_DATA_CHANGED_ENTER, this._context.WorkerRequest);
}
this.RaiseChangedEvents();
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_POST_DATA_CHANGED_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End Raise ChangedEvents");
this.Trace.Write("aspx.page", "Begin Raise PostBackEvent");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RAISE_POSTBACK_ENTER, this._context.WorkerRequest);
}
this.RaisePostBackEvent(this._requestValueCollection);
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RAISE_POSTBACK_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End Raise PostBackEvent");
}
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin LoadComplete");
}
this.OnLoadComplete(EventArgs.Empty);
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End LoadComplete");
}
if (this.IsPostBack && this.IsCallback)
{
this.PrepareCallback(text2);
}
else
{
if (!this.IsCrossPagePostBack)
{
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin PreRender");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_RENDER_ENTER, this._context.WorkerRequest);
}
this.PreRenderRecursiveInternal();
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_PRE_RENDER_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End PreRender");
}
}
}
}
if (this._asyncInfo == null || this._asyncInfo.CallerIsBlocking)
{
this.ExecuteRegisteredAsyncTasks();
}
this._request.ValidateRawUrl();
if (includeStagesAfterAsyncPoint)
{
if (this.IsCallback)
{
this.RenderCallback();
}
else
{
if (!this.IsCrossPagePostBack)
{
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "Begin PreRenderComplete");
}
this.PerformPreRenderComplete();
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End PreRenderComplete");
}
if (context.TraceIsEnabled)
{
this.BuildPageProfileTree(this.EnableViewState);
this.Trace.Write("aspx.page", "Begin SaveState");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_SAVE_VIEWSTATE_ENTER, this._context.WorkerRequest);
}
this.SaveAllState();
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_SAVE_VIEWSTATE_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End SaveState");
this.Trace.Write("aspx.page", "Begin SaveStateComplete");
}
this.OnSaveStateComplete(EventArgs.Empty);
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End SaveStateComplete");
this.Trace.Write("aspx.page", "Begin Render");
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RENDER_ENTER, this._context.WorkerRequest);
}
if (text != null)
{
this.ExportWebPart(text);
}
else
{
this.RenderControl(this.CreateHtmlTextWriter(this.Response.Output));
}
if (EtwTrace.IsTraceEnabled(5, 4))
{
EtwTrace.Trace(EtwTraceType.ETW_TYPE_PAGE_RENDER_LEAVE, this._context.WorkerRequest);
}
if (context.TraceIsEnabled)
{
this.Trace.Write("aspx.page", "End Render");
}
this.CheckRemainingAsyncTasks(false);
}
}
}
}
catch (.....}
}
我就是想要了解一下具象,所以才来发问的啊。
不过您上面给的是页面生命周期的,而我想要知道的是管道里面的步骤是如何触发的。
现在我已经翻到了源码,大体了解了一下,它里面的事件是通过ApplicationStepManager的BuildSteps方法给注册上的。这里面的细节有点多,等我好好整理整理,明天再写上来。 --------------------编程问答--------------------
希望你以后回答别人问题的时候不要答非所问,谢谢
补充:.NET技术 , ASP.NET