4

HttpContext.Current.ApplicationInstance.CompleteRequest は何もしていないようです。私は何が欠けていますか?

たとえば、興味深いイベントが発生するたびに CompleteRequest が呼び出されるにもかかわらず、以下のすべてのイベントは単純なテスト ページで実行されます。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace LifeCycle
{
    public partial class _Default_NoMasterPage : System.Web.UI.Page
    {
        private int count = 0;

        protected override void OnInit(EventArgs e)
        {
            nextLabel("InitBeforeBase");
            base.OnInit(e);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            nextLabel("Init");
        }

        protected override void OnInitComplete(EventArgs e)
        {
            nextLabel("InitCompleteBeforeBase");
            base.OnInitComplete(e);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            nextLabel("InitComplete");
        }

        protected override void OnLoad(EventArgs e)
        {
            nextLabel("OnLoadBeforeBase");
            base.OnLoad(e);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            nextLabel("OnLoad");
        }

        protected override void OnLoadComplete(EventArgs e)
        {
            nextLabel("OnLoadCompleteBeforeBase");
            base.OnLoadComplete(e);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            nextLabel("OnLoadComplete");
        }

        protected override void OnPreInit(EventArgs e)
        {
            // can't add a control to the page during OnPreInit as the other page control doesn't exist yet.
            base.OnPreInit(e);
        }

        private void nextLabel(string eventName)
        {
            string lbl = "" + ++count + " " + eventName + " at " + DateTime.Now.ToLongTimeString() + "";
            System.Web.UI.HtmlControls.HtmlGenericControl c = new HtmlGenericControl("div");
            c.InnerText = lbl;
            Page.Controls.Add(c);
        }
    }
}
4

1 に答える 1

7

したがって、完全なリクエストについて根本的な誤解があったことがわかりました。CompleteRequest は IIS HTTP パイプライン チェーンの残りの部分をスキップしますが、ASP.NET ページ ハンドラー イベント ライフサイクルは実行を終了します。

于 2012-07-05T15:19:18.067 に答える