在 ASP.NET Core 中,我使用了这样的身份验证:
启动:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/LogOut";
options.ExpireTimeSpan = TimeSpan.FromMinutes(43200); // 1 month
});
控制器:
var claims = new List<Claim>()
{
new Claim(ClaimTypes.NameIdentifier,user.UserId.ToString()),
new Claim(ClaimTypes.Name,user.Mobile.ToString()),
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var principal = new ClaimsPrincipal(identity);
var properties = new AuthenticationProperties
{
IsPersistent = true
};
我可以在 blazor 中使用这个方法吗?
我该怎么做?