Redirect with POST ?

Discussion in 'ASP .Net' started by Savanah, Feb 7, 2006.

  1. Savanah

    Savanah Guest

    Hello,

    I would like to call another page using POST method, something like this :

    Response.Redirect("http://www.mydomain.com/cgi-bin/log.dll?email="+tbLoginID").

    I set this in my page
    <form id="form1" method="post" runat="server

    But it's doen't work... :(

    ASP.NET cannot call any page n POST method ?
    Anyone can help me, thank in advance.

    Regards,
    Savanah
    Savanah, Feb 7, 2006
    #1
    1. Advertising

  2. No. The server has nothing to do with posting. The client is the one that
    packages the headers and sends the post. Using Redirect is nothing more
    that if the user had typed that URL in themselves.

    You can play tricks by sending the page contents down with the form fields
    filled in, then using JavaScript do a submit immediately.

    By the way, when you call Redirect, none of the page contents actually is
    sent to the browser. The control mechanism for redirecting is a single
    header field and so ASP.NET knows that there is no point in sending down any
    other content.

    "Savanah" <> wrote in message
    news:43e90b0f$0$290$...
    > Hello,
    >
    > I would like to call another page using POST method, something like this :
    >
    > Response.Redirect("http://www.mydomain.com/cgi-bin/log.dll?email="+tbLoginID").
    >
    > I set this in my page
    > <form id="form1" method="post" runat="server
    >
    > But it's doen't work... :(
    >
    > ASP.NET cannot call any page n POST method ?
    > Anyone can help me, thank in advance.
    >
    > Regards,
    > Savanah
    >
    Peter Rilling, Feb 7, 2006
    #2
    1. Advertising

  3. Savanah

    Savanah Guest

    Thank you for your reply.

    I try to use Server.Transfer but don't work too :(

    How I can send URL using POST method ?

    "Peter Rilling" <> a écrit dans le message de news:
    ...
    > No. The server has nothing to do with posting. The client is the one
    > that packages the headers and sends the post. Using Redirect is nothing
    > more that if the user had typed that URL in themselves.
    >
    > You can play tricks by sending the page contents down with the form fields
    > filled in, then using JavaScript do a submit immediately.
    >
    > By the way, when you call Redirect, none of the page contents actually is
    > sent to the browser. The control mechanism for redirecting is a single
    > header field and so ASP.NET knows that there is no point in sending down
    > any other content.
    >
    > "Savanah" <> wrote in message
    > news:43e90b0f$0$290$...
    >> Hello,
    >>
    >> I would like to call another page using POST method, something like this
    >> :
    >>
    >> Response.Redirect("http://www.mydomain.com/cgi-bin/log.dll?email="+tbLoginID").
    >>
    >> I set this in my page
    >> <form id="form1" method="post" runat="server
    >>
    >> But it's doen't work... :(
    >>
    >> ASP.NET cannot call any page n POST method ?
    >> Anyone can help me, thank in advance.
    >>
    >> Regards,
    >> Savanah
    >>

    >
    >
    Savanah, Feb 7, 2006
    #3
  4. Savanah

    Joerg Jooss Guest

    Thus wrote Peter,

    > No. The server has nothing to do with posting. The client is the one
    > that packages the headers and sends the post. Using Redirect is
    > nothing more that if the user had typed that URL in themselves.


    That's probably popular belief, but not true.

    HTTP defines status code 307 (Temporary Redirect) to redirect a POST as POST.
    The run-of-the-mill redirect everybody knows OTOH is 302
    (Found), which is what you get if you call HttpResponse.Redirect(). To make
    a sad story short, a 302 blindly turns POST into GET (first it was bug, today
    it's a feature).

    But it's not hard to implement a 307 redirect in ASP.NET:

    public void RedirectTemporary(string url) {
    Response.ClearContent();
    Response.StatusCode = 307;
    Response.StatusDescription = "Temporary Redirect";
    Response.RedirectLocation = ResolveClientUrl(url); // this assumes url
    is relative, like "~/PathTo/WebForm.aspx"
    Response.Flush();
    }

    Note: According to the HTTP 1.1 spec, a browser should warn the user before
    redirecting a POST request. Firefox follows the spec, IE6 doesn't.

    Cheers,
    --
    Joerg Jooss
    Joerg Jooss, Feb 7, 2006
    #4
  5. I learned something, cool.

    "Joerg Jooss" <> wrote in message
    news:...
    > Thus wrote Peter,
    >
    >> No. The server has nothing to do with posting. The client is the one
    >> that packages the headers and sends the post. Using Redirect is
    >> nothing more that if the user had typed that URL in themselves.

    >
    > That's probably popular belief, but not true.
    > HTTP defines status code 307 (Temporary Redirect) to redirect a POST as
    > POST. The run-of-the-mill redirect everybody knows OTOH is 302 (Found),
    > which is what you get if you call HttpResponse.Redirect(). To make a sad
    > story short, a 302 blindly turns POST into GET (first it was bug, today
    > it's a feature).
    >
    > But it's not hard to implement a 307 redirect in ASP.NET:
    >
    > public void RedirectTemporary(string url) {
    > Response.ClearContent();
    > Response.StatusCode = 307;
    > Response.StatusDescription = "Temporary Redirect";
    > Response.RedirectLocation = ResolveClientUrl(url); // this assumes url is
    > relative, like "~/PathTo/WebForm.aspx"
    > Response.Flush();
    > }
    >
    > Note: According to the HTTP 1.1 spec, a browser should warn the user
    > before redirecting a POST request. Firefox follows the spec, IE6 doesn't.
    >
    > Cheers,
    > --
    > Joerg Jooss
    >
    >
    >
    Peter Rilling, Feb 7, 2006
    #5
  6. Savanah

    Joerg Jooss Guest

    Thus wrote Peter,

    > I learned something, cool.


    You're welcome :)

    I just wish the ASP.NET product team would include this as another HttpResponse.Redirect()
    overload:

    HttpResponse.Redirect(string url, bool endResponse, HttpRedirectStatus status)

    Cheers,
    --
    Joerg Jooss
    Joerg Jooss, Feb 7, 2006
    #6
  7. Savanah

    Joerg Jooss Guest

    Thus wrote Joerg,

    > But it's not hard to implement a 307 redirect in ASP.NET:
    >
    > public void RedirectTemporary(string url) {
    > Response.ClearContent();
    > Response.StatusCode = 307;
    > Response.StatusDescription = "Temporary Redirect";
    > Response.RedirectLocation = ResolveClientUrl(url); // this assumes
    > url
    > is relative, like "~/PathTo/WebForm.aspx"
    > Response.Flush();
    > }


    Important note: The receiving web form must apply the directive EnableViewStateMac="false",
    otherwise Machine Authentication Check blows up in your face.

    Cheers,
    --
    Joerg Jooss
    Joerg Jooss, Feb 8, 2006
    #7
  8. Savanah

    Savanah Guest

    Thank you Joerg Joos.

    But you method don't work with .NET v1.1, I got error on ResolveClientUrl
    function

    I'm trying to use Server.Transfer like this :

    Server.Transfer("http://localhost/cgi-bin/webengine.dll/log?email="+tbMail.Text+"&pw="+tbPassword.Text");
    // Server redirection

    I got error message :
    "Error executing child request for
    "http://localhost/cgi-bin/webengine.dll/log?email="+tbMail.Text+"&pw="+tbPassword.Text"

    Why ? I can access at this page when copy and paste URL into IE ...

    Regards,
    Savanah


    "Joerg Jooss" <> a écrit dans le message de news:
    ...
    > Thus wrote Joerg,
    >
    >> But it's not hard to implement a 307 redirect in ASP.NET:
    >>
    >> public void RedirectTemporary(string url) {
    >> Response.ClearContent();
    >> Response.StatusCode = 307;
    >> Response.StatusDescription = "Temporary Redirect";
    >> Response.RedirectLocation = ResolveClientUrl(url); // this assumes
    >> url
    >> is relative, like "~/PathTo/WebForm.aspx"
    >> Response.Flush();
    >> }

    >
    > Important note: The receiving web form must apply the directive
    > EnableViewStateMac="false", otherwise Machine Authentication Check blows
    > up in your face.
    >
    > Cheers,
    > --
    > Joerg Jooss
    >
    >
    >
    Savanah, Feb 8, 2006
    #8
  9. Savanah

    Joerg Jooss Guest

    Thus wrote Savanah,

    > Thank you Joerg Joos.
    >
    > But you method don't work with .NET v1.1, I got error on
    > ResolveClientUrl function


    Yes, this a .NET 2.0 API.

    > I'm trying to use Server.Transfer like this :
    >
    > Server.Transfer("http://localhost/cgi-bin/webengine.dll/log?email="+tb
    > Mail.Text+"&pw="+tbPassword.Text");
    >
    > // Server redirection
    >
    > I got error message :
    > "Error executing child request for
    > "http://localhost/cgi-bin/webengine.dll/log?email="+tbMail.Text+"&pw="
    > +tbPassword.Text"
    > Why ? I can access at this page when copy and paste URL into IE ...


    That cannot work. HttpServerUtility.Transfer() only works within an ASP.NET
    application, and has *nothing* to do with HTTP redirects. If you cannot use
    ResolveClientUrl(), just remove the call and use absolute URLs with the method
    I presented.

    Cheers,
    --
    Joerg Jooss
    Joerg Jooss, Feb 9, 2006
    #9
  10. Savanah

    Savanah Guest

    so ASP.NET is unable to make simple page redirection using Post method ?!!



    "Joerg Jooss" <> a écrit dans le message de news:
    ...
    > Thus wrote Savanah,
    >
    >> Thank you Joerg Joos.
    >>
    >> But you method don't work with .NET v1.1, I got error on
    >> ResolveClientUrl function

    >
    > Yes, this a .NET 2.0 API.
    >> I'm trying to use Server.Transfer like this :
    >>
    >> Server.Transfer("http://localhost/cgi-bin/webengine.dll/log?email="+tb
    >> Mail.Text+"&pw="+tbPassword.Text");
    >>
    >> // Server redirection
    >>
    >> I got error message :
    >> "Error executing child request for
    >> "http://localhost/cgi-bin/webengine.dll/log?email="+tbMail.Text+"&pw="
    >> +tbPassword.Text"
    >> Why ? I can access at this page when copy and paste URL into IE ...

    >
    > That cannot work. HttpServerUtility.Transfer() only works within an
    > ASP.NET application, and has *nothing* to do with HTTP redirects. If you
    > cannot use ResolveClientUrl(), just remove the call and use absolute URLs
    > with the method I presented.
    >
    > Cheers,
    > --
    > Joerg Jooss
    >
    >
    >
    Savanah, Feb 10, 2006
    #10
  11. Savanah

    Joerg Jooss Guest

    Thus wrote Savanah,

    > so ASP.NET is unable to make simple page redirection using Post method
    > ?!!


    *Please* read what I've written.

    If you want to use the code I've presented with .NET 1.1, you need to drop
    the line with ResolveClientUrl() and simply work with absolute URLs, e.g.
    "http://host/PathTo/WebForm.aspx" instead of "~/PathTo/WebForm.aspx". Or
    is there another problem I'm missing?

    Cheers,
    --
    Joerg Jooss
    Joerg Jooss, Feb 10, 2006
    #11
  12. Savanah

    Lollo

    Joined:
    Sep 3, 2008
    Messages:
    1
    Thanks for the tip.
    But there is a way to add parameters.
    I don't want to put directly on the url because I have an url
    with more than 2,083 characters
    Thanks in advance.
    Lollo, Sep 4, 2008
    #12
  13. Savanah

    NumbLock

    Joined:
    Sep 4, 2009
    Messages:
    1
    Redirect with post

    I found this thread while I was trying to figure out how to programatically do a post to PayPal checkout page. I tried httpwebrequest and webclient and the redirect method posted here but could not get anything to work. Then I figured out a way to make it work.

    put an aspnet image button on the form and use the paypal graphic. Then when the user clicks submit, you can read the values off of the controls and then register them with clientscript.registerhiddenfield("cmd","_x-click") for example.

    Then in code change the form action with me.form1.action and change it to the paypal webscr script and change the method with me.form1.method="POST"

    Next create a string builder to hold the startup javascript and then use clientscript.registerstartupscript to cause the form to automatically redirect to PP with the hidden fields populated.

    Example:

    Me.form1.Action = "cant post URL but use the one for webscr @ paypal"
    Me.form1.Method = "POST"
    Dim sbScript As New Text.StringBuilder

    sbScript.AppendLine("<script type=""text/javascript"">")
    sbScript.AppendLine("document.form1.submit()")
    sbScript.AppendLine("</script>")

    ClientScript.RegisterStartupScript(Me.GetType, "Redir", sbScript.ToString)

    Hope this helps someone.

    Galen
    NumbLock, Sep 4, 2009
    #13
  14. Savanah

    mandarbansod

    Joined:
    Jan 3, 2010
    Messages:
    2
    about your post to redirect a page using post

    HI james

    I am using a webform which contains some ajax controls. In that page had set some hidden fields and on click of a button i want to save data to the database
    and send this information to a third party server.

    I am trying to post this using your post but it is throwing an error such as
    PageRequestManagerParserException error parsing near <!doctype ht'
    etc.

    Can you address this problem or suggest me some solution to this problem ?
    mandarbansod, Feb 15, 2010
    #14
  15. Savanah

    mandarbansod

    Joined:
    Jan 3, 2010
    Messages:
    2

    can u post a c# script for the same above ?
    mandarbansod, Feb 15, 2010
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. La Jesus
    Replies:
    9
    Views:
    1,298
    Gunnar Hjalmarsson
    Oct 27, 2003
  2. Radek G.
    Replies:
    4
    Views:
    4,090
    Radek G.
    Jun 18, 2004
  3. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,213
    Srowe1975
    Oct 15, 2008
  4. Sal
    Replies:
    1
    Views:
    372
  5. Ron Howard
    Replies:
    2
    Views:
    503
    Ron Howard
    Aug 11, 2004
Loading...

Share This Page