我正在尝试实现this用户提出的解决方案,以防止在我的应用程序中进行多次登录。
实际上我在我的Startup
类中声明,特别是在Configure
方法中这段代码:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
});
问题是,当我输入:AuthenticationType
我没有显示任何内容,因为CookieAuthenticationOptions
没有这个属性,这很奇怪,因为在documentation中属性不再存在。
如果我将鼠标悬停在CookieAuthenticationOptions
上,我可以看到这个命名空间:Assembly Microsoft.AspNetCore.Authentication.Cookies
。
PS:我正在使用ASP.NET CORE
app.UseCookieAuthentication()
已弃用ASP.NET Core 2.X,您应该在app.UseAuthentication()
方法中使用Configure
,但是您需要在ConfigureServices
方法中配置身份验证。
使用NuGet包Microsoft.AspNetCore.Mvc
版本2.1.0或更高版本应该像这样配置:
public void ConfigureServices(IServiceCollection services)
{
// Add the needed services, e.g. services.AddMvc();
services
.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
// Change the options as needed
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc();
}