您的位置:首页 > 编程语言

异常:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。

2011-03-10 11:21 549 查看
try
{
string url2 = Request.Url.Host;
if (url2.Trim().ToString() == "localhost")
{
Navi2GIS("http://localhost/MapPortal.aspx", type);
}
else
{
Navi2GIS("http://www.***.com/MapPortal.aspx", type);
}
}
catch (Exception e)
{
//这里报错???
}
private void Navi2GIS(string url, string type)
{
if (type == null || type == "")
{
url += "?apptoken=";
}
this.Response.Redirect(url);
}


每次都要走Catch();

在网上搜了一下才知道:

由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。}

System.Exception {System.Threading.ThreadAbortException}

因为在try-catch块内直接redirect的话
try-catch块就无法捕捉到异常

解决方法:

try
{
Response.Redirect("regok.aspx",false); //在Redirect里加个参数false就OK了
}
catch (System.Threading.ThreadAbortException e)
{
throw;
}

或者:

把Response.Redirect();语句从TRY中拿出也可以。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐