的Page_Load被多次调用,如果有在Page_Load中异常 [英] Page_Load is called multiple times if there is an exception in Page_Load
本文介绍了的Page_Load被多次调用,如果有在Page_Load中异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了下面code
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string data = Request.Form["postedData"];
if(someFunc(data))
Response.Redirect(SuccessURL, false);
else
Response.Redirect(FailureURL, false);
}
catch (Exception ex)
{
Response.Redirect(FailureURL, false);
}
}
}
它工作正常,除非在Page_Load异常。从我的理解code应的页面,FailureURL重定向在异常情况下。但在我的情况下,当有Page_Load中获取与发布的数据为NULL连连称为异常。任何线索?
It works fine unless there is an exception in the Page_Load. From my understanding the code should redirect the page to FailureURL in case of an exception. But in my case when there is an exception Page_Load gets called again and again with posted data as NULL. Any clue?
推荐答案
试着改变你的重定向code这样:
Try changing your redirect code to this:
修改:新增code,以避免ThreadAbortException
EDIT: Added code to avoid ThreadAbortException
Response.Redirect(FailureURL, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
这篇关于的Page_Load被多次调用,如果有在Page_Load中异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文