Max
Max

Reputation: 7119

Facebook Canvas POST ASP.net

Facebook is requiring all canvas apps to support HTTP POST in the iframe instead of GET. However, when I enable the feature, ASP.net complains that

The HTTP verb POST used to access path '/' is not allowed

For some reason Facebook requires a path that does not have an extension in it (for example it requires mydomain.com/random/ instead of mydomain.com/mypage.aspx).

How can I enable POST for aspx pages and the root (default) page in my web.config page so I can develop my app locally? I belive the configuration on IIS is more straightforward.

Thanks.

Upvotes: 3

Views: 644

Answers (3)

Max
Max

Reputation: 7119

I've found a workable solution by "rewriting" the requests to my root path in the Global.asax file. Works for development server, but will probably have to be removed in production:

void Application_BeginRequest(object sender, EventArgs e) {
  string p = Request.Path;
  if (p.Equals("/myapp/")) {
    var query = "?" + Request.QueryString.ToString();
    if (query.Equals("?")) {
      query = "";
    }
    Context.RewritePath("/myapp/Default.aspx" + query);
  }
}

Upvotes: 0

B Z
B Z

Reputation: 1

don't think you can... Instead of localhost, you actually have to push your app out to a server on the web that the FB servers can see, then your app should work.

Upvotes: 0

joelt
joelt

Reputation: 2680

Fascinating. I didn't believe it until I tried it. I was able to get rid of the exception when running this in VStudio's web server by adding <add verb="*" path="/" type="System.Web.UI.Page"/> to the <httpHandlers> section. The trick is, it didn't actually display the default page, or run the Page_Load event. I replaced System.Web.UI.Page with the namespace and type of my default page, and this time the Page_Load event ran, but the markup in the .aspx file seems to have been ignored. A call to Response.Write() in the Page_Load event did result in output to the browser.

So, maybe that's useful on its own, or maybe it points you in the right direction.

I also don't really know what side effects this might have, though, so proceed with caution.

Edit: The type you want can be found in the machine.config--System.Web.UI.PageHandlerFactory

Upvotes: 1

Related Questions