c# – try / catch块中的Response.Redirect异常
发布时间:2020-12-15 08:42:50 所属栏目:百科 来源:网络整理
导读:说,我有一个try / catch块封装了一大块代码,然后在其中的某个地方我需要调用Response.Redirect: protected void ButtonGo_Click(object sender,EventArgs e){ try { using(lockingMethod) { //Code... //Somewhere nested in the logic Response.Redirect(s
说,我有一个try / catch块封装了一大块代码,然后在其中的某个地方我需要调用Response.Redirect:
protected void ButtonGo_Click(object sender,EventArgs e) { try { using(lockingMethod) { //Code... //Somewhere nested in the logic Response.Redirect(strMyNewURL); //More code... } } catch(Exception ex) { LogExceptionAsError(ex); } } 在这种情况下会发生什么是Response.Redirect抛出一个异常,一些关于终止线程的事情,我认为这是该方法的“正常事件流”,但它作为错误记录在我的LogExceptionAsError中.所以我很好奇,有没有办法使Response.Redirect不抛出异常? 解决方法
尝试使用替代版本的Response.Redirect
Response.Redirect(strMyNewURL,false); 它将终止当前页面加载. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |