1
votes

I have a asp.net mvc web api app with ember and simplemembershipprovider. I am using the ember template and with it, ember app is created upon user successfully logged in in the home controller.

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

Sometimes user would click a link in an email with an id when visiting the site, if the url includes an id, upon successful login, I want to redirect user to a detail page base on the provided id in the url. An example would be http://siteURL.com/#/product/1412 . I am having a hard time figuring out how to do this. Since this is a client side ember route, MVC does not differentiate between this route and http://siteURL.com so it just ignores the redirect request. Here is what I have tried.

  1. assign the url in the login controller - nothing happens after json data is returned, stays in the login page and never hit the HomeController even though user is not authenticated.

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

  2. use response redirect. Same as #1
    Response.Redirect(returnUrl);

  3. Assigned url in home controller, same as above.
    if (User.Identity.IsAuthenticated)
    {
    returnUrl = "http://siteURL.com/#/product/1412";
    return View("App");
    }
    ViewBag.ReturnUrl = returnUrl;
    return View();
1

1 Answers

0
votes

Most browsers don't even send the # up to the server, so you won't have it to redirect. Here's a few options

  1. Don't use the hash, not every browser supports it, http://emberjs.com/guides/routing/specifying-the-location-api/

  2. Give them a fake address that redirects, http://siteURL.com/Redirect/product/1412

  3. inject that url into some js on the page that redirects on load