asp.net – Context.Response.End()和Thread正在中止
发布时间:2020-12-15 18:42:14 所属栏目:asp.Net 来源:网络整理
导读:我正在使用Context.Response.End来关闭响应,但会收到错误“Thread is beingorted”。 如何正确关闭响应而不触发异常? try { Context.Response.Clear(); Context.Response.ContentType = "text/html"; //Context.Response.ContentType = "application/json"
我正在使用Context.Response.End来关闭响应,但会收到错误“Thread is beingorted”。
如何正确关闭响应而不触发异常? try { Context.Response.Clear(); Context.Response.ContentType = "text/html"; //Context.Response.ContentType = "application/json"; JsonObjectCollection collection = new JsonObjectCollection(); collection.Add(new JsonNumericValue("resultcode",1)); collection.Add(new JsonStringValue("sourceurl",exchangeData.cUrl)); collection.Add(new JsonStringValue("filename",fileName)); collection.Add(new JsonStringValue("filesize",fileSize)); collection.Add(new JsonStringValue("fileurl",Common.GetPDFURL + outputFileName)); JsonUtility.GenerateIndentedJsonText = true; Context.Response.Write(collection); try { Context.Response.End(); } catch (ThreadAbortException exc) { // This should be first catch block i.e. before generic Exception // This Catch block is to absorb exception thrown by Response.End } } catch (Exception err) { } 自己解决,代码应该是这样的 try { Context.Response.End(); } catch (ThreadAbortException err) { } catch (Exception err) { } 解决方法
有没有特定的原因你不使用context.ApplicationInstance.CompleteRequest()而不是?
这种方法会使ASP.NET管道(EndRequest事件除外)导致短路,而不会抛出ThreadAbortException,因此您不需要额外的try / catch块,您也将体验更好的性能。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 我需要在哪一层编写代码
- asp.net – 如何提供不会被Hotmail删除的跟踪图像?
- ASP.NET:代码落后或没有代码落后?
- asp.net-mvc – 用于ASP.NET MVC 3的NuGet软件包
- 单元测试 – ASP .NET Web API控制器测试
- .Net Core in Docker极简入门(下篇)
- asp.net-web-api – Autofac,Owin,Webapi并注入Authorizati
- asp.net-mvc-3 – PrepareResponse().AsActionResult()抛出
- 在ASP.NET MVC中的jQuery与MicrosoftAjax
- asp.net-mvc – 如何从ActionExecuting过滤器中获取路由值?
推荐文章
站长推荐
- asp.net-mvc – Visual Studio 2013格式文档在MV
- ASP.NET Core 实现带认证功能的Web代理服务器
- asp.net – 如何更改Y轴标签字体大小?
- asp-classic – 你用什么来编辑和开发经典ASP
- 如何在asp.net核心中使用ViewDataDictionary和Ht
- asp.net – CookieContainer和Response.Cookies集
- IBatis.Net 老技术新研究
- asp.net – ScriptManager的EnablePartialRender
- 这应该是目前最快速有效的ASP.NET Core学习方式(
- asp.net-mvc – 值不能为空或为空.参数名称:con
热点阅读