JK.
JK.

Reputation: 21809

ASP.NET MVC-2 How can you recieve a POST from another website?

If another website is making a POST to my ASP.NET MVC 2 site, how can I capture it? Do I need to do anything to the routes?

eg The other site does this:

string url = "https://mvc2-site.com/TestReceive";  // that's my site's controller action

NameValueCollection inputs = new NameValueCollection();
inputs.Add("SessionId", "11111");
System.Net.WebClient Client = new WebClient();
byte[] result = Client.UploadValues(url, inputs);

How do I receive that POST on my site? I have tried:

public ActionResult TestReceive(FormCollection fc) {} // doesn't get hit

public ActionResult TestReceive(string SessionId) {} // method gets hit but session id is null

public ActionResult TestReceive() 
{
    var param = ControllerContext.RouteData.Values["parameter"].ToString(); // Values["parameter"] is null
} 

I do not control the other site and it must be a POST (not a webservice or anything else)

As another twist they will POST around 10 variables, but some are optional, so they may not be in the POST data.

Upvotes: 1

Views: 531

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

[HttpPost]
public ActionResult TestReceive(string sessionId) 
{
    ...
}

Also as there's no controller specified in the url you should make sure that the controller that contains this action is the default controller in the routes.

Upvotes: 1

Related Questions