我们的网站需要对接第三方 Web 服务进行身份验证并创建 cookie。我们不需要存储会员信息。在 Startup.cs 文件中,我有以下代码:
app.UseCookieAuthentication(options => {
options.AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.LoginPath = new PathString("/User/Login");
options.CookieName = "GEMSNCID";
options.ExpireTimeSpan = new System.TimeSpan(1, 0, 0);
});
登录方法为:
var claims = new[]
{
new Claim(ClaimTypes.Name, model.UserName),
new Claim(ClaimTypes.Country, "USA")
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
ClaimsPrincipal principal = new ClaimsPrincipal(identity);
Context.Response.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, principal);
return RedirectToAction("Index", "Home");
这个不起作用。可以有人帮忙吗?