在使用Response.Redirect("页面名称")或者Server.Transfer发生异常........."

     错误描述:在使用Response.Redirect("页面名称")或者Server.Transfer("页面地址")发生"Unable to evaluate expression because the code is optiomized or anative frame is on the call stack"异常信息。

     分析其原因:Response.End方法停止页的执行,并将该执行交换到应用程序的事件管线中的Application.EndRequest事件,Response.End后面的代码行将不执行。此问题主要出现在Response.Redirect()或者Server.Transfer()中,这是由于这两种方法都是内部调用了Response.End。

     解决办法:1,使用Response.Redirect("页面名称"),可以使用它的重载方法Response.Redirect(string urL,bool endResponse),对于endResponse参数传递false是取消对endResponse.End的内部调用。

                 2,使用Server.Transfer("页面地址"),可以使用Server.Execute方法替代。

posted @ 2009-02-06 11:55 破碎的梦 阅读(244) 评论(1) 编辑 收藏

 回复 引用 查看   
#1楼2010-01-29 12:36 | 飞鸽传书      
好方法。