在執行線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