1

After a user logs in with their Google profile I am trying to redirect them back to the home page, however it keeps redirecting to default.aspx.

The line above the return in the code below is what I am using to try to redirect.

[System.Web.Mvc.AcceptVerbs(HttpVerbs.Post)]
public ActionResult Logon(string loginIdentifier)
{
    if (!Identifier.IsValid(loginIdentifier))
    {
        ModelState.AddModelError("loginIdentifier", "The specified login identifier is invalid");
        return View();
    }
    else
    {
        var openId = new OpenIdRelyingParty();
        IAuthenticationRequest request = openId.CreateRequest(Identifier.Parse(loginIdentifier));

        // Require some additional data
        request.AddExtension(new ClaimsRequest
        {
            BirthDate = DemandLevel.NoRequest,
            Email = DemandLevel.Require,
            FullName = DemandLevel.Require
        });

        request.AddCallbackArguments("http://localhost:5977/Home/About", "http://localhost:5977/Home/About");
        return request.RedirectingResponse.AsActionResult();
    }
}

Any help would be appreciated, thanks!

4

1 回答 1

4

添加回调参数不会控制用户在登录完成后去哪里。相反,web.config 设置了默认的重定向行为:

    <authentication mode="Forms">
        <forms defaultUrl="/myhomepage"/>
    </authentication>

最终,这可以在您调用的控制器中被覆盖,RedirectFromLoginPage而不是使用SetAuthCookie然后手动重定向。但是无论如何,您通常应该在 web.config 文件中列出正确的主页 URL,在这种情况下,事情就会发生。

于 2012-05-30T02:45:39.707 回答