Does Facebook open a canvas app with a Post request? It's causing havoc with my MVC actions

岁酱吖の 提交于 2019-12-11 22:44:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!