我的移动网站允许用户向他们的Facebook好友发送AppRequest。这很管用。
当朋友接受AppRequest时,Facebook就会把朋友发送到我的网站上。这也很管用。
我的网站是一个ASP.Net MVC 4应用程序。我试图让我的路线,以承认即将到来的AppRequest接受,但我不知道如何做。
Facebook正在使用以下URL将朋友发送到我的网站:
source=notification
尽管我试图将路由映射到自定义控制器和操作,但它仍然被路由到Home/Index。以下是我迄今所做的未能奏效的工作:
注册路线:
routes.MapRoute(
name: "FacebookAppRequest",
url: "{ref}/{code}/{fb_source}", //This should match the URL above
defaults: new { controller = "Facebook", action ="FBAppRequestHandler"}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);控制器:
public class FacebookController : Controller
{
public FacebookController() {}
public ActionResult FBAppRequestHandler(
[Bind(Prefix = "ref")] string fbReferal,
[Bind(Prefix = "code")] string fbCode,
[Bind(Prefix = "fb_source")] string fbSource)
{
//Do some stuff with fbReferal, fbCode and fbSource
return View();
}发布于 2013-01-14 22:01:55
ref、code和fb_source作为查询字符串参数传递。他们不是路线的一部分。因此,您不可能期望{ref}/{code}/{fb_source}会与您的自定义路由匹配。如果请求是这样的话,情况就会是这样:
http://www.example.com/notif/abcdefg/notification由于实际路由如下所示(忘记查询字符串参数-它们不用于路由):
http://www.example.com/这里您所拥有的基本上是下面的url /。因此,您在这里最好的希望是修改您的默认路由,以便它能够路由到所需的控制器:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Facebook", action = "FBAppRequestHandler", id = UrlParameter.Optional }
);现在摆脱第一条路线--这没必要。
https://stackoverflow.com/questions/14327491
复制相似问题