我正在使用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) { }