Http POST and Redirect

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/2/2012 8:16:23 AM
Gravatar
Total Posts 81
Website Hobbyist and Software Engineer
Proud member of the mojoPortal team
www.doan.me

Http POST and Redirect

I am doing some work for a client where I need to do a Http POST and redirect a user to an URL of another site. I have done quite a bit of Googling and have found that apparently with ASP.NET this is not the easiest thing to do. I have found the following "sollutions", but not sure I would be really satisfied with either one as they seem to be a band-aid work around.

Posting Form Data from ASP.NET Page to Another URL
Redirect and POST in ASP.NET

The biggest problem with the first solution is that it just does the POST, but will not redirect the user along with the POST. The second one has an in between page that relies on javascript being enabled in the browser. I know that javascript being enable it pretty much relied for the majority of sites these days, but I just have a gut feeling that I am missing some easier way.

Also, I have not done a lot of experimentation within mojoPortal, but are there any gotchas or things I need to look out for if I try to implement the second solution or any other solution that may be suggested?

Thanks in advance!

Kerry

 

6/2/2012 9:24:22 AM
Gravatar
Total Posts 18439

Re: Http POST and Redirect

Hi Kerry,

There is nothing difficult about redirecting to another site is ASP.NET. If you post back to the current site ie the mojoPortal site, then do response.redirect you can easily redirect to another site. That redirect will be a GET request to the other site not a POST though, but that is going to be true using any server side technology. The only reason to do it that way is if you need to do some kind of server side processing before redirecting, otherwise you would just link to the other site.

If you need to post directly to another site then you can set the PostBackUrl property on an ASP:Button to make it post directly to the other site. But doing that is not going to give any opportunity for server side processing on your own site since it pposts directly from the browser to the other site.

POST to another site has to happen from the browser not the server. It is possible to do a server to server post but that isn't going to involve the browser so no browser navigation happens.

If you need to post first to the current site and then to the remote site the problems would be the same in any server side technology not just asp.net, you would have to first post back to the current site and then in the response render some javascript that will post to the other site after the page loads again in the browser.

The second approach article is doing just that but its also adding another form to the page which is kind of going against the grain of asp.net web forms where there can be one and only one form element on a page, he is embedding a new form inside the existing one as literal markup. If I were implementing something like that I would not add a form I would use javascript to change the action on the existing form in javascript using the id of the existing form  (view the source of the page to get the id) and then submit the existing form posting back to the remote url. Adding a form the way he does in that article seems error prone to me because it can make the closing tag of the inner form seem like the closing tag of the main form to the asp.net runtime, and putting one form inside another form is invalid markup.

Essentially when you set the PostBackUrl property on asp:Button its setting up the javascript to change the action on the form so you wouldn't really even need to write your own javascript for that. You could put an invisible asp:imagebutton ie using a 1 pixel gif as the image, set the PostbackUrl on the image button to the remote page and then just write javascript that clicks the button after the page loads and add that during postback. Technically there is no redirect in this solution, its just postback to the current site then after the page loads from the postback response using javascript to post again to a new remote url. A true redirect involves a 302 (object moved) response code.

Hope that helps,

Joe

You must sign in to post in the forums. This thread is closed to new posts.