C# webservice HttpContext.Current.Response.End() 引发线程中断的处理

xiaoxiao2021-02-28  90

1.可以分别带入err参数看返回:

2.流程走向

3.事例代码

[WebMethod]         public void helloword(int err)         {             string result = "{\"status\":\"success\"}";             try{                 result = jsonP(result);                                  //提前结束                 if(2==err)                 {                     result = jsonP("{\"status\":\"success direct\"}");                     return;                 }                                   string cj = "1111";                                  //模拟异常                 if(0!=err){                     string xxx = "12";                     int i = Convert.ToInt32("jetaime");                 }             }             catch(Exception ex)             {                 result = jsonP("\"status\":\"err\"");             }finally{                 HttpContext.Current.Response.Write(result);                 HttpContext.Current.Response.End();             }         }

     publicstring jsonP(string str)         {                          return "([{"+str+"}])";         }          

转载请注明原文地址: https://www.6miu.com/read-48069.html

最新回复(0)