What about the next statement afeter response.redirect andserver.transfer?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lander

    What about the next statement afeter response.redirect andserver.transfer?

    I've seen many people have written code like this:

    response.redire ct();
    return;

    or

    server.transfer ();
    return;

    I doubt whether the statement "return;" will be hit? I think it's
    redundant, isn't it?
  • Mark Rae [MVP]

    #2
    Re: What about the next statement afeter response.redire ct and server.transfer ?

    "lander" <lostlander.tom @gmail.comwrote in message
    news:8c826552-7a97-42ce-8204-68a0f52a9949@s8 g2000prg.google groups.com...
    I doubt whether the statement "return;" will be hit? I think it's
    redundant, isn't it?
    No.


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • George Ter-Saakov

      #3
      Re: What about the next statement afeter response.redire ct and server.transfer ?

      You right.
      return will never bit hit in this case.

      But I still always put it for clarity

      George.

      "lander" <lostlander.tom @gmail.comwrote in message
      news:8c826552-7a97-42ce-8204-68a0f52a9949@s8 g2000prg.google groups.com...
      I've seen many people have written code like this:
      >
      response.redire ct();
      return;
      >
      or
      >
      server.transfer ();
      return;
      >
      I doubt whether the statement "return;" will be hit? I think it's
      redundant, isn't it?

      Comment

      • Mark Rae [MVP]

        #4
        Re: What about the next statement afeter response.redire ct and server.transfer ?


        "George Ter-Saakov" <gt-nsp@cardone.com wrote in message
        news:%23vD9nOrg IHA.5348@TK2MSF TNGP03.phx.gbl. ..
        "lander" <lostlander.tom @gmail.comwrote in message
        news:8c826552-7a97-42ce-8204-68a0f52a9949@s8 g2000prg.google groups.com...
        >I've seen many people have written code like this:
        >>
        >response.redir ect();
        >return;
        >>
        >or
        >>
        >server.transfe r();
        >return;
        >>
        >I doubt whether the statement "return;" will be hit? I think it's
        >redundant, isn't it?
        >
        You are right.
        return will never bit hit in this case.
        That's incorrect...

        protected void Page_Load(objec t sender, EventArgs e)
        {
        if (this == that)
        {
        Response.Redire ct("mypage.aspx ", false);
        //return;
        }

        if (this != that)
        {
        // this *will* run if the above return is not unremmed...
        }
        }


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • George Ter-Saakov

          #5
          Re: What about the next statement afeter response.redire ct and server.transfer ?

          Yes, there is a second parameter which will change default behavior.

          But default behavior would terminate the execution.

          So in
          Response.Redire ct("mynewpage.a spx")
          return;

          "return" is unnecessary

          George.

          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:uvvAuZrgIH A.4320@TK2MSFTN GP06.phx.gbl...
          "George Ter-Saakov" <gt-nsp@cardone.com wrote in message
          news:%23vD9nOrg IHA.5348@TK2MSF TNGP03.phx.gbl. ..
          >
          >"lander" <lostlander.tom @gmail.comwrote in message
          >news:8c82655 2-7a97-42ce-8204-68a0f52a9949@s8 g2000prg.google groups.com...
          >>I've seen many people have written code like this:
          >>>
          >>response.redi rect();
          >>return;
          >>>
          >>or
          >>>
          >>server.transf er();
          >>return;
          >>>
          >>I doubt whether the statement "return;" will be hit? I think it's
          >>redundant, isn't it?
          >>
          >You are right.
          >return will never bit hit in this case.
          >
          That's incorrect...
          >
          protected void Page_Load(objec t sender, EventArgs e)
          {
          if (this == that)
          {
          Response.Redire ct("mypage.aspx ", false);
          //return;
          }
          >
          if (this != that)
          {
          // this *will* run if the above return is not unremmed...
          }
          }
          >
          >
          --
          Mark Rae
          ASP.NET MVP
          http://www.markrae.net

          Comment

          • Mark Rae [MVP]

            #6
            Re: What about the next statement afeter response.redire ct and server.transfer ?

            "George Ter-Saakov" <gt-nsp@cardone.com wrote in message
            news:uNo40%23rg IHA.4196@TK2MSF TNGP04.phx.gbl. ..
            >>You are right.
            >>return will never bit hit in this case.
            >>
            >That's incorrect...
            >>
            >protected void Page_Load(objec t sender, EventArgs e)
            >{
            > if (this == that)
            > {
            > Response.Redire ct("mypage.aspx ", false);
            > //return;
            > }
            >>
            > if (this != that)
            > {
            > // this *will* run if the above return is not unremmed...
            > }
            >}
            >
            Yes, there is a second parameter which will change default behavior.
            >
            But default behavior would terminate the execution.
            Yes, that's true, but that would raise a
            System.Threadin g.ThreadAbortEx ception...


            --
            Mark Rae
            ASP.NET MVP


            Comment

            • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

              #7
              Re: What about the next statement afeter response.redire ct and ser

              thats generally what you want.

              overwise you need to override the render event, set a flag that a redirect
              was done, then cancel the render (and maybe prerender). you may need to also
              override the event firing logic, as you probably don't want to raise events
              after a redirect.

              if you don't do this, all the page processing happens, and html is
              downloaded to the browser, but ignored because of the redirect header.

              -- bruce (sqlwork.com)


              "Mark Rae [MVP]" wrote:
              "George Ter-Saakov" <gt-nsp@cardone.com wrote in message
              news:uNo40%23rg IHA.4196@TK2MSF TNGP04.phx.gbl. ..
              >
              >You are right.
              >return will never bit hit in this case.
              >
              That's incorrect...
              >
              protected void Page_Load(objec t sender, EventArgs e)
              {
              if (this == that)
              {
              Response.Redire ct("mypage.aspx ", false);
              //return;
              }
              >
              if (this != that)
              {
              // this *will* run if the above return is not unremmed...
              }
              }
              Yes, there is a second parameter which will change default behavior.

              But default behavior would terminate the execution.
              >
              Yes, that's true, but that would raise a
              System.Threadin g.ThreadAbortEx ception...
              >
              >
              --
              Mark Rae
              ASP.NET MVP

              >
              >

              Comment

              • lander

                #8
                Re: What about the next statement afeter response.redire ct andserver.trans fer?

                On 3ÔÂ10ÈÕ, ÏÂÎç11ʱ19·Ö, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
                "George Ter-Saakov" <gt-...@cardone.com wrote in message
                >
                news:uNo40%23rg IHA.4196@TK2MSF TNGP04.phx.gbl. ..
                >
                >
                >
                >
                >
                >You are right.
                >return will never bit hit in this case.
                >
                That's incorrect...
                >
                protected void Page_Load(objec t sender, EventArgs e)
                {
                if (this == that)
                {
                Response.Redire ct("mypage.aspx ", false);
                //return;
                }
                >
                if (this != that)
                {
                // this *will* run if the above return is not unremmed...
                }
                }
                >
                Yes, there is a second parameter which will change default behavior.
                >
                But default behavior would terminate the execution.
                >
                Yes, that's true, but that would raise a
                System.Threadin g.ThreadAbortEx ception...
                >
                --
                Mark Rae
                ASP.NET MVPhttp://www.markrae.net- Òþ²Ø±»ÒýÓÃÎÄ×Ö -
                >
                - ÏÔʾÒýÓõÄÎÄ×Ö -
                Hi mark, would you pls explain *why* to us? Thanks really.

                Comment

                Working...