authentication - 如何在 asp.net 5 中设置 Auth cookie

标签 authentication asp.net-core

尝试在 asp.net5 中制作一种非常简单的身份验证形式,但似乎他们删除了表单例份验证。我还可以使用什么来进行非常简单的身份验证?

提前致谢

最佳答案

你可以这样做。

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

关于authentication - 如何在 asp.net 5 中设置 Auth cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32373211/

相关文章:

c# - .NET Core : IFileProvider. GetDirectoryContents 递归不起作用

.net - 微服务 API 网关与微服务框架

asp.net - 如何使用 HttpClient 在 ASP.Net C# 中禁用分块传输编码

asp.net - 找不到与命令 dotnet-projectmodel-server 匹配的可执行文件

authentication - Salesforce 作为 OpenId 身份验证提供商

Python:创建登录系统

reactjs - Asp.Net Core Api 授权

asp.net-core - ASP.NET 核心 blazor webassembly 获取用于 Identity Server 4 Postman 测试的 token

php - 不使用数据库的 Lumen HTTP 基本身份验证

python - Django:HttpResponseRedirect 不工作