开发者

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 acti开发者_JAVA技巧on

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜