【问题标题】:DotNetOpenAuth redirect to HomepageDotNetOpenAuth 重定向到主页
【发布时间】:2012-05-29 13:26:02
【问题描述】:

在用户使用他们的 Google 个人资料登录后,我试图将他们重定向回主页,但它一直重定向到 default.aspx。

下面代码中返回上面的行是我用来尝试重定向的。

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

任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 我能解决这个问题,不用担心!
  • 为了子孙后代,如果您发布自己的答案,这样其他有此问题的人可以弄清楚,那就太好了。

标签: asp.net-mvc-3 openid dotnetopenauth


【解决方案1】:

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

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-09
  • 2015-05-30
相关资源
最近更新 更多