我正在尝试使用 Context.Response.End
来关闭响应,但收到错误 "线程被中止"
。
我如何正确关闭响应,而不触发异常?
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) {
}