Why HttpResponse.AppendHeader does not apply if Redirect is used?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • newsgroup.poster@gmail.com

    Why HttpResponse.AppendHeader does not apply if Redirect is used?

    I need to set a custom http header before perform http redirection.

    I do

    response.Append Header("aCustom Header", "aCustomVal ue")
    response.Redire ct("anUrl")

    and my added header doesn't show up, it seems to be erased, if I
    remove the redirect, it does.

    Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
    library/t9dwyts4.aspx) it doesn't explain why the behaviour is
    occuring.

    How can I workarround this issue?

    Am I forced to implement my own redirect?

    Thanks,

    Gauthier Segay
  • Damien

    #2
    Re: Why HttpResponse.Ap pendHeader does not apply if Redirect is used?

    On Oct 8, 10:52 am, newsgroup.pos.. .@gmail.com wrote:
    I need to set a custom http header before perform http redirection.
    >
    I do
    >
    response.Append Header("aCustom Header", "aCustomVal ue")
    response.Redire ct("anUrl")
    >
    and my added header doesn't show up, it seems to be erased, if I
    remove the redirect, it does.
    >
    Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
    library/t9dwyts4.aspx) it doesn't explain why the behaviour is
    occuring.
    >
    How can I workarround this issue?
    >
    Am I forced to implement my own redirect?
    >
    Thanks,
    >
    Gauthier Segay
    There is a clue in the documentation, under Exceptions:

    HttpException A redirection is attempted after the HTTP
    headers have been sent

    So I think you're going to have to set the RedirectLocatio n property
    and choose an appropriate status to send.

    Damien

    Comment

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

      #3
      RE: Why HttpResponse.Ap pendHeader does not apply if Redirect is used?

      a Response.Redire ct clears all content. you will need to write your own
      redirect.

      -- bruce (sqlwork.com)


      "newsgroup.post er@gmail.com" wrote:
      I need to set a custom http header before perform http redirection.
      >
      I do
      >
      response.Append Header("aCustom Header", "aCustomVal ue")
      response.Redire ct("anUrl")
      >
      and my added header doesn't show up, it seems to be erased, if I
      remove the redirect, it does.
      >
      Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
      library/t9dwyts4.aspx) it doesn't explain why the behaviour is
      occuring.
      >
      How can I workarround this issue?
      >
      Am I forced to implement my own redirect?
      >
      Thanks,
      >
      Gauthier Segay
      >

      Comment

      • newsgroup.poster@gmail.com

        #4
        Re: Why HttpResponse.Ap pendHeader does not apply if Redirect is used?

        Thanks to both for your replies, I've added a comment to the msdn
        library

        if anyone have pointers to some freely usable implementation of
        redirect that allows more flexibility, that would be of great use.

        In the mean time I've hacked something simpler for my limited usecase.

        On Oct 8, 4:25 pm, Damien <Damien_The_Unb elie...@hotmail .comwrote:
        On Oct 8, 10:52 am, newsgroup.pos.. .@gmail.com wrote:
        >
        >
        >
        I need to set a custom http header before perform http redirection.
        >
        I do
        >
        response.Append Header("aCustom Header", "aCustomVal ue")
        response.Redire ct("anUrl")
        >
        and my added header doesn't show up, it seems to be erased, if I
        remove the redirect, it does.
        >
        Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
        library/t9dwyts4.aspx) it doesn't explain why the behaviour is
        occuring.
        >
        How can I workarround this issue?
        >
        Am I forced to implement my own redirect?
        >
        Thanks,
        >
        Gauthier Segay
        >
        There is a clue in the documentation, under Exceptions:
        >
        HttpException           A redirection is attempted after the HTTP
        headers have been sent
        >
        So I think you're going to have to set the RedirectLocatio n property
        and choose an appropriate status to send.
        >
        Damien

        Comment

        • George

          #5
          Re: Why HttpResponse.Ap pendHeader does not apply if Redirect is used?

          To do redirect you need to do 4 lines of code.

          Request.Status = "302 Moved Permanently";
          Request.StatusC ode = 302;
          Request.AddHead er("Location", sUrl);
          rq.End();

          George.

          <newsgroup.post er@gmail.comwro te in message
          news:40989aa6-217d-4152-a99e-ec8f435c3b5f@d1 g2000hsg.google groups.com...
          Thanks to both for your replies, I've added a comment to the msdn
          library

          if anyone have pointers to some freely usable implementation of
          redirect that allows more flexibility, that would be of great use.

          In the mean time I've hacked something simpler for my limited usecase.

          On Oct 8, 4:25 pm, Damien <Damien_The_Unb elie...@hotmail .comwrote:
          On Oct 8, 10:52 am, newsgroup.pos.. .@gmail.com wrote:
          >
          >
          >
          I need to set a custom http header before perform http redirection.
          >
          I do
          >
          response.Append Header("aCustom Header", "aCustomVal ue")
          response.Redire ct("anUrl")
          >
          and my added header doesn't show up, it seems to be erased, if I
          remove the redirect, it does.
          >
          Looking at Redirect documentation (http://msdn.microsoft.com/en-us/
          library/t9dwyts4.aspx) it doesn't explain why the behaviour is
          occuring.
          >
          How can I workarround this issue?
          >
          Am I forced to implement my own redirect?
          >
          Thanks,
          >
          Gauthier Segay
          >
          There is a clue in the documentation, under Exceptions:
          >
          HttpException A redirection is attempted after the HTTP
          headers have been sent
          >
          So I think you're going to have to set the RedirectLocatio n property
          and choose an appropriate status to send.
          >
          Damien

          Comment

          Working...