代码之家  ›  专栏  ›  技术社区  ›  w0051977

用户可以单击登录超链接吗?

  •  0
  • w0051977  · 技术社区  · 7 年前

    我可以将用户从MVC核心应用程序中注销,如下所示:

    public IActionResult Logout()
    {
        return SignOut("Cookies", "oidc");
    }
    

    将调用Identity server,用户将按预期注销。是否可以通过指定链接来登录用户?我意识到,如果用户访问网站的安全区域,就会被自动转发。但是,用户是否有可能说自己希望登录(返回的url是主页,即home/Index)。

    0 回复  |  直到 7 年前
        1
  •  0
  •   Chris Pratt    7 年前

    你的问题不是很清楚,但如果我能正确理解你,你在寻找 returnUrl 查询参数。例如,如果要将用户发送到 /foo

    <a href="/login?returnUrl=/foo">Go to Foo, but login first</a>
    
        2
  •  0
  •   d_f    7 年前

    这个问题还不清楚,但我会尝试:

    在你的 Account

    [Authorized] //actually you don't need this attribute here when have it on controller level
    //All this action does is authenticating the user and redirecting to home/Index
    public ActionResult AutoLogin()
    {
      return RedirectToAction("Index", "Home");
    }
    

    然后在布局中添加:

    @Html.ActionLink(
           "Login", "AutoLogin", "Account", routeValues: new{}, htmlAttributes: new {id = "loginLink"})