1、使用Ajax接收数据,在返回Response.Write()后应该调用Response.End()才能将数据写入到调用的页面,才能被jQuery的回调函数获取到返回的JSON数据

2、在try--catch里面不能用Response.End(),否则会报错:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。

 

在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作。

如果将Response.End()放在try...catch中,catch会捕捉Thread.CurrentThread.Abort()产生的异常System.Threading.ThreadAbortException。

解决方法(任选一个):

1. 在catch中排除ThreadAbortException异常,示例代码如下:

try
{
Response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
catch (Exception ex)
{
Response.Write(ex);
}

2. 用Context.ApplicationInstance.CompleteRequest()结束当前请求,代码如下:

protected void Page_Load(object sender, EventArgs e)
{
try
{
Response.Write("Hello world!");
this.Page.Visible = false;
Context.ApplicationInstance.CompleteRequest();
}
catch (Exception ex)
{
Response.Write(ex);
}
}
 posted on 2017-04-12 10:26  纳米程序员  阅读(1691)  评论(0编辑  收藏  举报