0

我的移动网站允许用户发送AppRequest给他们的Facebook朋友。这是行得通的。在ASP.Net中路由Facebook AppRequest MVC 4

当朋友接受AppRequest时,Facebook将朋友发送到我的网站。这也是工作。

我的网站是一个ASP.Net MVC 4应用程序。我试图让我的路线识别传入的AppRequest接受,但我无法弄清楚如何做到这一点。

Facebook正在使用该URL发送朋友到我的网站:

http://www.example.com/?ref=notif&code=abcdefg&fb_source=notification

这种状态越来越排到首页/指数,尽管我试图映射到一个定制的控制器和行动路线。以下是我迄今已没有工作做:

注册途径:

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

回答

1

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

现在摆脱了第一条路线的 - 这是没有必要的。