lloydphillips
lloydphillips

Reputation: 2855

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

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'. :(

Upvotes: 0

Views: 702

Answers (1)

Jacob
Jacob

Reputation: 3639

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);
}

Upvotes: 2

Related Questions