gpt4 book ai didi

c# - IApplicationBuilder 不包含 UseIdentity 的定义

转载 作者:行者123 更新时间:2023-12-01 23:01:36 25 4
gpt4 key购买 nike

我正在按照一个示例在 AspNet Core 3.0 上配置 AspNet Core Identity

这是 StartUp.cs 文件的代码

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Users_WEB_APP.Models;

namespace Users_WEB_APP
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:ASPNET_IDENTITY:ConnectionString"]));
services.AddIdentity<AppUser, IdentityRole>()
.AddEntityFrameworkStores<AppIdentityDbContext>();
services.AddMvc(options => options.EnableEndpointRouting = false);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseStatusCodePages();
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseIdentity();
app.UseMvcWithDefaultRoute();
}
}
}

但是在排队时app.UseIdentity();我收到错误

'IApplicationBuilder' does not contain a definition for 'UseIdentity', and no accessible extension method 'UseIdentity' accepting a first argument of type 'IApplicationBuilder' could be found (are you messing a using directive or an assembly reference?)

我做错了什么?

最佳答案

文档称,从 ASP.NET Core 2.2 开始,UseIdentity现已过时, UseAuthentication应该使用

This method is obsolete and will be removed in a future version. The recommended alternative is UseAuthentication(IApplicationBuilder)

https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.builderextensions.useidentity?view=aspnetcore-2.2

关于c# - IApplicationBuilder 不包含 UseIdentity 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59518292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com