到Response.End()不会中止当前线程 [英] Response.End () doesn't abort current thread

查看:620
本文介绍了到Response.End()不会中止当前线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么ASP.NET可能不会在到Response.End中止当前线程()?

更新:原因是有code,虽然写得不好,这是获得到Response.End后执行()。我从来没有见过的情况下到Response.End()并没有从停止执行当前线程。

 
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
        Response.Clear();
        的Response.Redirect(地方,真正的);
        到Response.End();        //其他一些code获取的在此执行
}


解决方案

正如您所指出的那样,方法到Response.End被定义为:

 公共无效结束()
{
  如果(this._context.IsInCancellablePeriod){
    InternalSecurityPermissions.ControlThread.Assert();
    Thread.CurrentThread.Abort(新HttpApplication.CancelModuleException(假));
  }
  否则,如果(!this._flushing)
  {
    this.Flush();
    this._ended = TRUE;
    如果(this._context.ApplicationInstance!= NULL){
      this._context.ApplicationInstance.CompleteRequest();
    }
  }
}

调试在Page_Load方法一个破发点一个相当简单的Web应用程序,我可以看到调用堆栈包括行:


  

System.Web.dll中! System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep步= {} System.Web.HttpApplication.CallHandlerExecutionStep,楼盘布尔completedSynchronously = TRUE)+ 0x4c字节


反映到 CallHandlerExecutionStep 我可以看到属性 IsCancellable 的定义是:

 布尔HttpApplication.IExecutionStep.IsCancellable {
  获得{
    返回(this._application.Context.Handler是IHttpAsyncHandler)!;
  }
}

有关.aspx页默认的处理程序是从输出的 PageHandlerFactory 这实现了IHttpHandler,不IHttpAsyncHandler - 这将导致 IsCancellable 返回true(因为实际上它在我的测试应用程序)。

你有没有配置为在您的根web.config或者一个进一步向上堆栈使用异步处理程序,而不是一个不同的HttpHandler?您是否正在使用更新面板例如与部分回发?

Anybody know why ASP.NET might not abort the current thread with a Response.End()?

Update: Reason being that there is code, albeit not well written, that is getting executed after Response.End(). I've never seen a case where Response.End () didn't stop the current thread from executing.


protected void Page_Load(object sender, EventArgs e)
{
        Response.Clear();
        Response.Redirect("somewhere", true);
        Response.End();

        //Some other code get's executed here
}

解决方案

As you've pointed out, the method Response.End is defined as:

public void End()
{
  if (this._context.IsInCancellablePeriod) {
    InternalSecurityPermissions.ControlThread.Assert();
    Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false));
  }
  else if (!this._flushing)
  {
    this.Flush();
    this._ended = true;
    if (this._context.ApplicationInstance != null) {
      this._context.ApplicationInstance.CompleteRequest();
    }
  }
}

Debugging a fairly simple web app with a break point in the Page_Load method, I can see the call stack includes the line:

System.Web.dll! System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.CallHandlerExecutionStep}, ref bool completedSynchronously = true) + 0x4c bytes

Reflecting into CallHandlerExecutionStep I can see that the property IsCancellable is defined as:

bool HttpApplication.IExecutionStep.IsCancellable {
  get {
    return !(this._application.Context.Handler is IHttpAsyncHandler);
  }
}

The default handler for .aspx pages is the output from the PageHandlerFactory which implement IHttpHandler, not IHttpAsyncHandler - which would result in IsCancellable returning true (as indeed it does in my test app).

Have you configured a different HttpHandler in either your root web.config or one further up the stack to use an Async Handler instead? Are you using Update Panels with Partial Postbacks for example?

这篇关于到Response.End()不会中止当前线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆