问题
I've created an MVC app that has a Friend view which has a post action, see code below. When I'm loading the page for the first time my POST method is getting called. I found this http://developers.facebook.com/docs/canvas/post/ and just wondered if someone could clarify that Facebook is calling the post method to pass in data. In which case the best way around my problem is to rename my POST action?
Here's my code with unnecessary bits stripped out:
public ActionResult Friend()
{
ViewData["Success"] = false;
return View("Friend");
}
[HttpPost]
public ActionResult Friend(FacebookViewModel model)
{
ViewData["Success"] = true;
return View("Friend", model);
}
When calling the app ViewData being printed out to the screen is printing 'true'. :(
回答1:
I believe Facebook does this for security reasons, I remember seeing something about the switch to POST for canvas apps a while back.
Looks like they also announced it in this blog post.
The best option is probably to change your Action as you suggested:
[HttpPost]
public ActionResult CanvasLoad(FacebookPostLoadViewModel model)
{
// Do your load logic and show your view or RedirectToAction("Otherview");
return View("Friend", model);
}
来源:https://stackoverflow.com/questions/5353261/does-facebook-open-a-canvas-app-with-a-post-request-its-causing-havoc-with-my