Is it possible to post a form from one MVC site so that it invokes the POST action in a controller on another site ? I can do a GET easily, but a browser redirect is always a GET as per my understanding and I am unable to invoke the target site's POST action.
e.g. http:/siteA.com/test invokes http://siteB.com/result/signin ... in the ResultController, the Get version of the "SignIn" action gets invoked, but I need the "Post" version to be invoked as I need to pass in parameters in the POST header.
Currently I am resorting to using a GET and am passing params. using the query string which is not ideal for my scenario. Any help here would be appreciated.
You could POST using a simple form:
<form method="post" action="http://othersite.com/controller/action">
<!-- some input fields containing the values to post -->
<input type="hidden" name="param1" value="value1" />
<input type="submit" value="Post to other site" />
</form>
I used AJAX to invoke the target and bundled in the necessary parameters to post in there.
Related
In my web forms project (a forum) I have a form that is accessed through a link from another page, a link which includes parameters. for example:
EditPost.aspx?mid=0
When the page is loaded, the form hasn't yet been submitted and Request.QueryString contains the URL parameters I loaded the page with. However, after I send the form, Request.QueryString conatins the values of the form fields. This is a problem because I need the URL parameters after the form is sent.
The question is, how do i make the page send me those URL parameter with the form information?
If I'm approaching this wrong, and I'm supposed to keep the URL parameters from when the page is first loaded, let me know how.
Thanks!
Edit:
<form action="" id="f_editComment" name="f_editThread" method="post" onsubmit="return true;">
<%=ThreadTitle %>
<textarea id="body" name="body" runat="server"></textarea>
<input type="submit" id="submit" name="submit" />
</form>
I am trying to do something from scratch in asp
I would like to get something like below. From basic hard coded values.
http://localhost:2478/Default.aspx?phone=905123456&order=123456
After that I want to use this parameter in my variables for SQLquery
I am new to asp.net and vb , I'm learning. Can you please explain me in details? Any helps will be appreciate.
Can you please provide any basic code from where I can start
Based on your latest comments:
<form method="get" action="default.aspx">
<input type="text" name="phone" />
<input type="text" name="order" />
<input type="submit" value="submit" />
</form>
Key points:
method=get (fields are in url instead of body)
note that the form above doesn't have runat=server (more below) - it's a plain HTML Form on plain HTML page
in the context of ASP.Net Web forms, you may run into issues particularly if you are using Master Pages (you can't nest forms, and a Master page is a container for your entire page).
ASP.Net forms do POSTbacks - re: method=post
You can use/add plain forms in an ASP.Net page as long as you don't nest them (outside of the server side ASP.Net form).
If you have no choice (e.g. Master Page), you'll have to construct the Querystring manually after a POSTback, then Response.Redirect to some other target (adding the querystring manually).
there are other non-ASP.Net-y ways of doing it - e.g. javascript, but that a different story
I created a WebRequest to POST information. My objective is to emulate in C# a PayPal "buy now" button which is in html.
How do I get the redirect when sending the WebRequest? Simply having Response.Redirect doesn't work because I have to have the redirect with the information.
The code of the button I'm trying to emulate is:
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
...
</form>
You can not do redirect with post.
What you can do: Make the actually post direct to the paypal, or redirect to a second page that re-create all the post data, and make automatic post with javascript.
An example of how to create a page with parameters that make automatic post.
http://www.codeproject.com/Articles/37539/Redirect-and-POST-in-ASP-NET
Not sure you can do what you want from code behind. I had a similar situation where I had the form like yours besides the normal ASP.net form. I hid the non-ASP.net form through CSS so it's not in the user's face and then I triggered the POST via javascript (I put a button inside the form and then called buttonX.click(); )
I have an ASP form that allows for a database to be searched. The form has a search box (id = street) where people enter their street name and the form will provide a response.
I had a standard HTML form on a bog-standard page on a different website that passed the street variable to the form and the ASP form grabbed this from the URL and this worked fine.
We have since had to update the form to place session data in the URL rather than in a cookie but sadly now the form on the bog-standard page no longer works. The variable does not seam to be recognised by the form.
The format of the sessioned URL is http://www.adomainname.com/(S(mbta4i55vubtxn55gnzhdt55))/form/search.aspx
<form action='http://www.adomainname.com/form/search.aspx' method="post">
<input type="text" value="High Street" id="street" name="street" />
<input type="submit" />
</form>
Has anyone had this issue?
I'm not clear about what you're trying to do yet, but I'll take a shot at the answer...
If you want the street in the URL, change the method to "get".
I have a classic asp application. I want to post a contest form from that page to an Asp.Net form. The reason is that I want to use a lot of logic i have built into an Asp.Net page for validation before entering into the database and I don't know asp very well. Not to mention asp.Net being more secure.
What's the best way to accomplish this goal? My thoughts are as follows:
My asp Page:
<html>
<body>
<form action="/Contests/entry.aspx" method="post">
Name: <input type="text" name="fname" size="20" />
Last Name: <input type="text" name="lname" size="20" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
aspx page is running in a Virtual Directory and would handle anything posted to it.
Is this possible, or does aspx prevent this kind of thing?
I ( preferably ) don't want to create the form in aspx as my colleague wants to have control of the page and build the html himself and I don't want the hassle of constantly changing it.
Are there caveats I need to consider?
What roadblocks will I run into?
How do I access the Posted Form Values? Request.Form?
Yes it is possible. In general, a POST is a POST. So you can post from a PHP page to a .NET page if you wanted. You would access the Request.Form variables just as you do now. You will have to look at the ASP Classic page to see the names of the post items but in general, you can access them as if you had pasted from .NET page.
This can be done and works fine. You will access the Posted Form values as you said via Request.Form.
I think the biggest caveat is that you will need to handle invalid data in some way - typically with a webform the .aspx page would be displayed again with validation errors, but that would likely be inappropriate for your circumstance. Probably you will need to redirect them back to the .asp page with query string parameters indicating the failures and the page will need code allowing it to fill in the form fields with their previous values and display the error message.
How about calling an ASP.NET webservice from classic asp?
https://web.archive.org/web/20210125161040/http://www.4guysfromrolla.com/webtech/070302-1.shtml