try
        {
            String a="3";
            Response.Redirect("B.aspx");
        }
        catch (Exception)
        {
            Response.Redirect("A.aspx");
        }
以前没有注意,上面的代码为什么“Response.Redirect("A.aspx");”总会执行,如果不是 Response.Redirect的话,其它操作则不会。

解决方案 »

  1.   

    Response.Redirect("B.aspx",false);是否存在B页面 
      

  2.   

    try里执行一段代码,会返回一个参数,然后Response.Redirect("B.aspx?id=参数");
      

  3.   

    Response.Redirect能判断成不成功吗,try成功了String a="3"也没什么意义啊,已经到另一个页面了
      

  4.   

    那是不是先出来参数值,try后面搞Response.Redirect
      

  5.   


    加了False是可以了。不加为什么还会执行“Response.Redirect("A.aspx");”呢?
      

  6.   

    你为什么会认为Response.Redirect("B.aspx");会出错,我可以告诉你,这段代码就不可能出错,Response.Redirect就是向客户端浏览器发送一个重定向的Http消息,不管你的这个页面是否存在,服务器对于本次请求的执行已经完毕.所以就是你看到的永远都是到b.aspx,不管这个页面是否存在,都是客户端的事情,这次请求已经完成.你是在是猜不出来你到底想要个什么效果,不过你可以尝试一下用Server.Transfer方法,这个方法和Response.Redirect的区别在于一个是在当前请求中把页面的处理交给另一个aspx页面处理,而后者是交由客户端再发起一次跳转页面的请求.
      

  7.   

    catch (Exception ex)
    把这个异常的ex错误信息输出来看一下就知道问题出在哪里了
      

  8.   

    糟糕,我看错了,你先看一下Exception,是不是你前面已经有response的输出了,response.Redirec必须要求在这个操作之前不能有任响应输出,因为他是在返回的请求头中包含跳转信息,如果你之前已经有response输出,请求头就已经发送到客户端了,所以你再执行这个命令就会报错.比如 一下伪代码哈
    Response.Write("Hello world!");
    Response.flash();
    Response.Redirect()--exception
    你跟一下,就明白了
      

  9.   

    报的是这个错误
    System.Threading.ThreadAbortException: 正在中止线程。
       在 System.Threading.Thread.AbortInternal()
       在 System.Threading.Thread.Abort(Object stateInfo)
       在 System.Web.HttpResponse.End()
       在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
       在 System.Web.HttpResponse.Redirect(String url)我的代码是try
            {
                String id="";
                if (new PostService().Proc_newPost(user.ID, this.txtTitle.Text.Trim(), this.txtContent.Value, this.ddlPlate.SelectedValue, ref id)>0)
                {
                    Response.Redirect("B.aspx?ID=" + id);
                }
            }
            catch (Exception er)  
            {
                string error= er.ToString();
                Response.Redirect("A.aspx");
            }
    Response.Redirect("B.aspx?ID=" + id);加了Flase参数就可以了。我不明白的是Response.Redirect("B.aspx?ID=" + id);在这里为什么会引发异常?
      

  10.   

    + false是不中止本次Response,
    把代码弄详细点
      

  11.   


    上面的代码已经是全部代码了?执行一个存储过程,得到一个ID,再跳转。跟那个存储过程里面没有关系。你测试一下,什么也不做        try
            {            Response.Redirect("B.aspx");
            }
            catch (Exception)
            {
                Response.Redirect("A.aspx");
            }
    我是一个Button触发的,也会有错误的。
      

  12.   

    这个是异常信息
    报的是这个错误
    System.Threading.ThreadAbortException: 正在中止线程。
      在 System.Threading.Thread.AbortInternal()
      在 System.Threading.Thread.Abort(Object stateInfo)
      在 System.Web.HttpResponse.End()
      在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
      在 System.Web.HttpResponse.Redirect(String url)
      

  13.   

    在try块里用if else判断就行了,为啥搞那么麻烦。
      

  14.   

    string redirectPath = null;
                try
                {
                    redirectPath = "B.aspx";
                }
                catch
                {
                    redirectPath = "A.aspx";
                }            Response.Redirect(redirectPath);
      

  15.   


    只是为什么Response.Redirect会引发异常,其它操作则不会。
      

  16.   

    我测试过
    Random ran = new Random();
                if (ran.Next(1000) % 2 == 0)
                {
                    Response.Redirect("A.aspx");
                }
                else
                {
                    Response.Redirect("B.apsx");
                }
    这样并不会有任何错误,猜想是应该之前的Response.Redirect在Catch块中,而编译器编译后会有两个代码块进行Response.Redirect的操作,具体的原因只有微软的人才能说的清楚了,也说不定是一个bug哦!呵呵