如果您对为什么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报错)
- .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(…) 将表单重定向到新页面时,出现错误:
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有什么区别?
解决方法
如果您正在为WP8或Windows应用商店开发XAML应用程序,请使用Windows.System版本.
.net – 使用异步,等待与System.Threading.Thread.Sleep
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”的第一次机会异常
但是当我尝试调试应用程序时,会给我任何错误 –
mscorlib.dll中出现了“System.Threading.ThreadAbortException”类型的第一个机会异常
它不会在任何特定的代码行错误。它给出任何代码行(不确定)..然后网页显示 – “服务器应用程序不可用”错误的错误。
即使我试图在即时窗口/快速观察中解析/执行一些声明 – 它给我上面的错误..
例如,我在XElement中加载了一个xml文档(超过10000行),当我尝试通过xpath检查一些属性值为XElementObj.XPathSelectElement(“/ asdf / asd / wqer / xyz”)..它给出了上面的错误(不是所有的时间,而是随机)。
任何人有任何想法这个..请帮助。
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?
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.
解决方法
尝试使用此行:
<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?的相关知识,请在本站搜索。
本文标签: