Ember + web api单页重定向

时间:2013-12-19 20:45:14

标签: api redirect model-view-controller ember.js routes

我有一个带有ember和simplemembershipprovider的asp.net mvc web api应用程序。我正在使用ember模板,使用ember应用程序是在用户成功登录家庭控制器时创建的。

    public ActionResult Index(string returnUrl)
    {
        if (User.Identity.IsAuthenticated)
        {
            return View("App");
        }
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

有时用户在访问网站时会点击带有ID的电子邮件中的链接,如果网址包含ID,则在成功登录后,我想根据网址中提供的ID将用户重定向到详细信息页面。一个例子是http://siteURL.com/#/product/1412。我很难搞清楚如何做到这一点。由于这是客户端ember路由,因此MVC不区分此路由和http://siteURL.com,因此它只是忽略重定向请求。这是我尝试过的。

  1. 在登录控制器中分配url - 返回json数据后没有任何反应,保留在登录页面中,即使用户未经过身份验证,也不会点击HomeController。

    FormsAuthentication.SetAuthCookie(model.UserName,model.RememberMe);
    returnUrl =“http://siteURL.com/#/product/1412”;
    返回Json(new {success = true,redirect = returnUrl});

  2. 使用响应重定向。与#1相同 的Response.Redirect(RETURNURL);

  3. 在家庭控制器中指定网址,与上述相同。
            if(User.Identity.IsAuthenticated)
            {
           returnUrl =“http://siteURL.com/#/product/1412”;
                返回视图(“App”);
            }
            ViewBag.ReturnUrl = returnUrl;
            return View();

1 个答案:

答案 0 :(得分:0)

大多数浏览器甚至不会将#up发送到服务器,因此您不会将其重定向。这里有几个选项

  1. 请勿使用散列,并非所有浏览器都支持散列,http://emberjs.com/guides/routing/specifying-the-location-api/

  2. 给他们一个重定向的虚假地址,http://siteURL.com/Redirect/product/1412

  3. 将该网址注入负载重定向的网页上的某些js