【问题标题】:How to set a Auth cookie in asp.net 5如何在 asp.net 5 中设置 Auth cookie
【发布时间】:2015-11-29 03:29:44
【问题描述】:

试图在 asp.net5 中创建一种非常简单的身份验证形式,但似乎他们删除了表单身份验证。我还能用什么来进行非常简单的身份验证?

提前致谢

【问题讨论】:

标签: authentication asp.net-core


【解决方案1】:

你可以这样做。

if (authUser.Username == "admin" && authUser.Password == "admin")
    {
        var claims = new[] { new Claim("name", authUser.Username), new Claim(ClaimTypes.Role, "Admin") };
        var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
        Context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

        return Redirect("~/Home/Index");
    }

示例代码 - https://github.com/anuraj/CookieAuthMVCSample

【讨论】:

猜你喜欢
  • 2014-10-10
  • 1970-01-01
  • 2016-09-16
  • 2015-09-21
  • 2016-07-23
  • 1970-01-01
  • 1970-01-01
  • 2013-11-25
  • 2017-01-07
相关资源
最近更新 更多