Redirect with POST ?

S

Savanah

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
 
P

Peter Rilling

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.
 
S

Savanah

Thank you for your reply.

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

How I can send URL using POST method ?
 
J

Joerg Jooss

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,
 
P

Peter Rilling

I learned something, cool.

Joerg Jooss said:
Thus wrote Peter,


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,
 
J

Joerg Jooss

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,
 
J

Joerg Jooss

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,
 
S

Savanah

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
 
J

Joerg Jooss

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,
 
J

Joerg Jooss

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top