GVKun编程网logo

为什么 Response.Redirect 会导致 System.Threading.ThreadAbortException?(response.sendredirect报错)

16

如果您对为什么Response.Redirect会导致System.Threading.ThreadAbortException?和response.sendredirect报错感兴趣,那么这篇文章一

如果您对为什么 Response.Redirect 会导致 System.Threading.ThreadAbortException?response.sendredirect报错感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解为什么 Response.Redirect 会导致 System.Threading.ThreadAbortException?的各种细节,并对response.sendredirect报错进行深入的分析,此外还有关于.net – Windows.System.Threading.ThreadPool和System.Threading.ThreadPool有什么区别?、.net – 使用异步,等待与System.Threading.Thread.Sleep、.net – 在mscorlib.dll中发生类型“System.Threading.ThreadAbortException”的第一次机会异常、asp.net – 在Windows Azure上的HTTP处理程序中是否需要ThreadAbortException?的实用技巧。

本文目录一览:

为什么 Response.Redirect 会导致 System.Threading.ThreadAbortException?(response.sendredirect报错)

为什么 Response.Redirect 会导致 System.Threading.ThreadAbortException?(response.sendredirect报错)

当我使用 Response.Redirect(…) 将表单重定向到新页面时,出现错误:

mscorlib.dll 中出现“System.Threading.ThreadAbortException”类型的第一次机会异常
mscorlib.dll
中出现“System.Threading.ThreadAbortException”类型的异常,但未在用户代码中处理

我对此的理解是,错误是由网络服务器中止调用 response.redirect 的页面的其余部分引起的。

我知道我可以添加第二个参数Response.Redirect,称为 endResponse。如果我将 endResponse 设置为
True,我仍然会收到错误,但如果我将其设置为
False,那么我不会。我很确定这意味着网络服务器正在运行我重定向的页面的其余部分。至少可以说这似乎是低效的。有一个更好的方法吗?除了Response.Redirect或者有没有办法强制旧页面停止加载我不会得到的地方ThreadAbortException

答案1

小编典典

正确的模式是使用 endResponse=false 调用 Redirect 重载,并调用以告诉 IIS 管道,一旦您返回控制权,它应该直接进入
EndRequest 阶段:

Response.Redirect(url, false);Context.ApplicationInstance.CompleteRequest();

Thomas Marquardt的这篇博客文章提供了更多详细信息,包括如何在 Application_Error 处理程序中处理重定向的特殊情况。

.net – Windows.System.Threading.ThreadPool和System.Threading.ThreadPool有什么区别?

.net – Windows.System.Threading.ThreadPool和System.Threading.ThreadPool有什么区别?

Windows Phone 8 SDK文档未描述Windows.System.Threading.ThreadPool和System.Threading.ThreadPool之间的区别.除了明显的API差异之外,两者之间有什么区别吗?例如,他们使用相同的线程池吗?如果存在潜在的差异,我应该使用哪些时间?

解决方法

Windows.System.Threading.ThreadPool在基于XAML的应用程序中使用是“安全的”,System.Threading.ThreadPool是所有.net应用程序类型可用的标准API.

如果您正在为WP8或Windows应用商店开发XAML应用程序,请使用Windows.System版本.

.net – 使用异步,等待与System.Threading.Thread.Sleep

.net – 使用异步,等待与System.Threading.Thread.Sleep

我开始使用.NET4.5进行异步处理等待.所有示例似乎使用以下来模拟长期操作:
await Task.Delay(3000);

现在我的长期计算真的很像:

System.Threading.Thread.Sleep(3000)

例如:

for(i=0;i<1000000000;i++)
    i=i*2;

如何使这个工作与异步等待?现在看来,我可以’只’使用诸如webrequest,WCF等的方法与这个伟大的新方法.

我在哪里错过了点?

解决方法

await Task.Run(() => Thread.Sleep(10000))

会工作,但它没有意义

.net – 在mscorlib.dll中发生类型“System.Threading.ThreadAbortException”的第一次机会异常

.net – 在mscorlib.dll中发生类型“System.Threading.ThreadAbortException”的第一次机会异常

我正在开发asp.net应用程序..当我尝试编译和运行应用程序;它运行成功。

但是当我尝试调试应用程序时,会给我任何错误 –

mscorlib.dll中出现了“System.Threading.ThreadAbortException”类型的第一个机会异常

它不会在任何特定的代码行错误。它给出任何代码行(不确定)..然后网页显示 – “服务器应用程序不可用”错误的错误。

即使我试图在即时窗口/快速观察中解析/执行一些声明 – 它给我上面的错误..

例如,我在XElement中加载了一个xml文档(超过10000行),当我尝试通过xpath检查一些属性值为XElementObj.XPathSelectElement(“/ asdf / asd / wqer / xyz”)..它给出了上面的错误(不是所有的时间,而是随机)。

任何人有任何想法这个..请帮助。

我有类似的东西,从另一个问题发现了 this answer:

If you want to pinpoint where the
exceptions are occurring,you can
select the Debug->Exceptions menu
item,and in the dialog that appears,
check the first checkBox for “Common
Language Runtime Exceptions”. This
will make the debugger break as soon
as an exception occurs instead of only
breaking on unhandled exceptions.

This is also one reason why it is generally a bad idea to catch generic exceptions unless you are clearly logging the information caught.

asp.net – 在Windows Azure上的HTTP处理程序中是否需要ThreadAbortException?

asp.net – 在Windows Azure上的HTTP处理程序中是否需要ThreadAbortException?

我在一个“小”计算实例中托管在 Windows Azure上的ASP.NET HTTP处理程序.它处理大型二进制文件的下载和上传.在该Web角色中没有其他任何内容,并且根据指南配置了2个实例.当从具有慢速连接的计算机完成下载并且我尝试一次执行多次下载以阻塞客户端的带宽时,有时我会在处理程序中获得ThreadAbortException,最常见的是在.Write到Response.OutputStream期间(我事先设置了Response.BufferOutput = false).堆栈跟踪如下:

System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Web.Hosting.UnsafeIISMethods.MgdExplicitFlush(IntPtr context)
   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
   at System.Web.HttpResponse.Flush(Boolean finalFlush)
   at System.Web.HttpWriter.WriteFromStream(Byte[] data,Int32 offset,Int32 size)
   at MyHandler.ProcessGetRequest(HttpContext context)
   at MyHandler.ProcessRequest(HttpContext context)

(Stream.Write调用显然是内联的,因此它不会显示在堆栈跟踪中).

为什么线程被中止?我猜我正在达到某种超时(可能是套接字写入超时),正在以正常方式中止线程,以便ASP.NET运行时处理它?

请注意,它是一个单独的HTTP处理程序,而不是.aspx / .cshtml页面或MVC控制器,在我的代码中没有任何地方我触及Response.End,Response.Redirect或Server.Transfer.

解决方法

当您上传大文件时,IIS会尝试读取请求流,如果它阻塞超过5分钟,则会导致IIS最终抛出ThreadAbortException.

尝试使用此行:

<httpRuntime maxRequestLength="2097150" executionTimeout="3600"/>

也请尝试以下建议:http://cutesoft.net/forums/permalink/77440/77438/ShowThread.aspx#77438

今天关于为什么 Response.Redirect 会导致 System.Threading.ThreadAbortException?response.sendredirect报错的讲解已经结束,谢谢您的阅读,如果想了解更多关于.net – Windows.System.Threading.ThreadPool和System.Threading.ThreadPool有什么区别?、.net – 使用异步,等待与System.Threading.Thread.Sleep、.net – 在mscorlib.dll中发生类型“System.Threading.ThreadAbortException”的第一次机会异常、asp.net – 在Windows Azure上的HTTP处理程序中是否需要ThreadAbortException?的相关知识,请在本站搜索。

本文标签: