try / catch块中的Response.Redirect异常 [英] Response.Redirect exception inside the try/catch block

查看:110
本文介绍了try / catch块中的Response.Redirect异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我有一个try / catch块,其中封装了一大段代码,然后在其中某个地方我需要调用Response.Redirect:

Say, I have a try/catch block that encapsulates a large block of code and then somewhere in it I need to call Response.Redirect as such:

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 不抛出异常?

What happens in this case is that Response.Redirect throws an exception, something about terminating the thread, which I believe is a "normal flow of events" for that method, but it gets logged in my LogExceptionAsError as an error. So I was curious, is there any way to make Response.Redirect not throw exception?

推荐答案

尝试使用 Response.Redirect

Response.Redirect(strMyNewURL, false);

它将终止当前页面加载。

It will terminate the current page loading.

这篇关于try / catch块中的Response.Redirect异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆