Bristol.NET
Bristol.NET

Reputation: 59

HTML form post to asp.net controller across domains

I've created an ASP.NET MVC 5 web application that must receive a post from an external site (within the same corporate intranet). I've set up my controller method and created another web application to simulate the post. The posting page form looks like this:

<form action="http://localhost:12345/Home/MethodName" method="post">
    <input type="text" id="fullName" value="Joseph B. Blow" />
    <input type="text" id="dateOfBirth" value="3/4/1977" />
    <input type="submit" value="Submit" />
</form>

I start my "receiver" app in debug mode and set a break point on the first line in "/Home/MethodName" and the breakpoint is hit. MethodName looks like this:

[HttpPost]
[ValidateInput(false)]
public ActionResult MethodName()
{
    ...code here
}

When I check the Request.Form object in MethodName, it's completely empty. Using developer tools in the browser the Content-Length is 0. I've tried creating a custom model class that has the properties fullName and dateOfBirth and using that as the sole parameter in MethodName but the properties of the object are always null. I also tried to use the FormCollection object, it contained no keys. Another attempt I made was to use a StreamReader object and use it on the Request.InputStream object to see if that would pull the posted values in.

I might consider using an ajax call to post the data but the issue with that is the user must also be redirected to the page. There is a company security policy against not using the querystring to pass data from site-to-site (I know, a post isn't necessarily more secure than a get, but dems the rules).

This doesn't seem like it should be this hard but I'm having a bear of a time with it. If anyone has done something similar or could point me in another direction to get these values passed from one page to another, I would greatly appreciate it.

Thanks in advance.

Upvotes: 0

Views: 824

Answers (1)

Bristol.NET
Bristol.NET

Reputation: 59

I'm a big dummy. All I had to do to get it to work was to include the name attribute in the form inputs, then the controller could see the values. In other words instead of

<input type="text" id="fullName" value="Joseph B. Blow" />

I changed it to

<input type="text" NAME="fullName" value="Joseph B. Blow" />

Only reason I'm exposing myself as a complete tool is in hopes that it will help someone else that may be having the same issue.

Upvotes: 1

Related Questions