我正在按照一个示例在上配置AspNet Core身份的示例AspNet Core 3.0

这是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();
我遇到了错误



我在做什么错了?

最佳答案

文档说,从ASP.NET Core 2.2开始, UseIdentity 现在已过时,应改为使用 UseAuthentication



https://docs.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/

10-17 02:32