在执行线ThreadAbortException在asp.net
Server.Transfer("Payment.aspx?vpc_ChannelId=2", true);
,从而指出了这个答案https://stackoverflow.com/a/1252119/1169180 & https://stackoverflow.com/a/11130517/1169180
我改变了我的代码
protected void Page_Load(object sender, EventArgs e)
{
try
{
UserContext conObj = new UserContext();
HttpContext CurrContext = HttpContext.Current;
if (!IsPostBack)
{
// Code
}
else
{
string userContext = hdnContextObj.Value;
conObj = JsonConvert.DeserializeObject<UserContext>(userContext);
CurrContext.Items.Add("Context", conObj);
try
{
Server.Transfer("Payment.aspx?vpc_ChannelId=2", true);
}
catch (ThreadAbortException xObj)
{
}
finally
{
Server.Transfer("Payment.aspx?vpc_ChannelId=2", true);
}
}
}
catch (Exception xObj)
{
Response.Write("Exception : " + xObj.Message);
}
}
我收到错误
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
服务器转移
我仍然收到同样的例外,在捕捉块
也如这里指出的http://support.microsoft.com/kb/312629/EN-US/我用Server.Execute
但它没有重定向到Payment.aspx
页,而只是刷新。
你的try/catch是什么都不做,你正赶上,然后reshowing相同的异常,这是一样的根本没有抓住它。如果你想吞下异常,那么不要扔进你的catch块。 – 2014-10-27 09:49:41
@BenRobinson:即使我删除catch块的投掷。当行终于得到执行,异常获得最外面的catch块 – Shaggy 2014-10-27 10:08:06