百度空间 | 百度首页 
 
查看文章
 
try语句块中的页面跳转问题
2009-04-22 18:59
今天第一次碰到Response.Redirect报错,不是无法找到页面,而是弹出错误:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

在网上查找问题解决方法如下:
摘自http://blog.csdn.net/skyaspnet/archive/2008/03/18/2194793.aspx

问题原因及解决办法:

原因
Response.End 方法停止页的执行,并将该执行变换到应用程序的事件管线中的 Application_EndRequest 事件。 Response.End 后面的代码行将不执行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,这是由于这两种方法都在内部调用 Response.End。
解决方案
若要解决此问题,请使用下列方法之一:
对于 Response.End,调用 ApplicationInstance.CompleteRequest 方法而不调用 Response.End,以便跳过 Application_EndRequest 事件的代码执行。
对于 Response.Redirect,使用重载 Response.Redirect(String url, bool endResponse),对 endResponse 参数它传递 false以取消对 Response.End 的内部调用。例如:
   Response.Redirect ("nextpage.aspx", false);
如果使用这种解决方法,Response.Redirect 后面的代码将得到执行。
对于 Server.Transfer,请改用 Server.Execute 方法。
状态
这种现象是设计使然。
解决后的代码:
try
{
Response.Redirect("UserManager",false);
}
catch
{
Response.Redirect("Error.aspx");
}


类别:.net | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu