gpt4 book ai didi

ASP.NET ApplicationInstance.CompleteRequest 不起作用?

转载 作者:行者123 更新时间:2023-12-01 10:05:39 27 4
gpt4 key购买 nike

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);
}
}
}

最佳答案

所以事实证明我对 completerequest 有一个根本的误解。 CompleteRequest 跳过 IIS HTTP 管道链的其余部分,但 ASP.NET 页面处理程序事件生命周期完成运行,因为它只是 HTTP 管道链的一部分,并且没有任何东西告诉这部分停止。

关于ASP.NET ApplicationInstance.CompleteRequest 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11006662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com