asp.net – Context.Response.End()和Thread正在中止
发布时间:2020-05-23 12:32:10 所属栏目:asp.Net 来源:互联网
导读:我正在使用Context.Response.End来关闭响应,但会收到错误“Thread is beingorted”。 如何正确关闭响应而不触发异常? try { Context.Response.Clear(); Context.Response.ContentType = text/html; //Context.Response.ContentType = app
|
我正在使用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 – 在MVC WebApi中的方法如何映射到http动词?
- asp.net – 配置节“system.servicemodel”无法读取,因为它
- asp.net-mvc-3 – 不支持使用相同的DbCompiledModel来针对不
- 如何在asp.net c#中计算网站访问者数量
- asp.net-mvc – 如何将MEF与ASP.NET MVC 4和ASP.NET Web AP
- asp.net – Ajax Control Toolkit正在加载太多脚本资源
- 使asp.net应用程序符合IPv6标准
- 使用ASP.Net MVC3中的jQuery动态填充下拉列表
- asp.net-mvc – 如何处理MVC5中的配置和代码中的404错误?
- asp.net-mvc-3 – asp.net mvc3返回原始html来查看
推荐文章
站长推荐
- asp.net-web-api – 使用OWIN SelfHost和Windows
- asp.net-mvc – 当我使用Validator.TryValidateO
- 如何在ASP.NET MVC 4 Beta中禁用Javascript/CSS缩
- asp.net – jqGrid:使用多种方法来过滤数据
- asp.net-mvc-3 – MVC3:不将属性映射到DB列的属
- asp.net – FormsAuthentication.SetAuthCookie(
- asp.net-mvc – 抛出一个404像StackOverflow的,没
- asp.net – Microsoft JScript运行时错误:’Sys
- asp.net – 在资源文件中使用HTML
- asp.net-mvc – Web API和ASP MVC之间的主要区别
热点阅读
