如何设置asp.net 5验证的cookie [英] How to set a Auth cookie in asp.net 5

查看:240
本文介绍了如何设置asp.net 5验证的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在asp.net5身份验证的一种很简单的形式,但好像他们取消了形式的认证。我还能用做一个非常简单的身份验证?

Trying to make a very simple form of authentication in asp.net5 but seems like they removed the form authentication. What else could I use to make a very simple authentication?

在此先感谢

推荐答案

您可以做这样的事情。

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");
    }

样code - <一个href=\"https://github.com/anuraj/CookieAuthMVCSample\">https://github.com/anuraj/CookieAuthMVCSample

这篇关于如何设置asp.net 5验证的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆