IApplicationBuilder不包含UseIdentity的定义 - c#

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

这是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”不包含“ UseIdentity”的定义,
并且没有可访问的扩展方法“ UseIdentity”接受第一个
可以找到类型为“ IApplicationBuilder”的参数(您是否一团糟
使用指令或程序集引用?)

我做错了什么?

参考方案

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

该方法已过时,将在以后的版本中删除。推荐的替代方法是UseAuthentication(IApplicationBuilder)

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

ASP.NET Core Singleton实例与瞬态实例的性能 - c#

在ASP.NET Core依赖注入中,我只是想知道注册Singleton实例是否会比注册Transient实例更好地提高性能?在我看来,对于Singleton实例,创建新对象和相关对象只需花费一次时间。对于Transient实例,此成本将针对每个服务请求重复。因此Singleton似乎更好。但是,在Singleton上使用Transient时,我们可以获得多…

ASP.NET Core-在Singleton注入上存储库依赖项注入失败 - c#

我正在使用SoapCore为我的ASP.NET Core MVC应用程序创建Web服务。我正在使用Entity Framework Core和简单的存储库模式来获取我的数据库数据。我通过Startup.cs中的.AddSingleton()注入存储库类:services.AddSingleton<IImportRepository, ImportRep…

如何在ASP.NET Core Web应用程序中增加JSON反序列化MaxDepth限制 - c#

我们正在将ASP.NET Core 2.1与.NET Framework 4.6.2结合使用。我们有一个客户需要向我们的Web应用程序发送一个很大程度上嵌套的json结构。当他们进行此调用时,我们将输出以下日志并返回错误: 读取器的MaxDepth超过了32。路径“ super.long.path.to property”,第1行,位置42111。”我浏览了…

ASP.NET MVC Core 3.0 API将枚举序列化为字符串 - c#

如何在ASP.NET MVC Core 3.0中将Enum字段序列化为String而不是Int?我不能用旧的方式做。services.AddMvc().AddJsonOptions(opts => { opts.JsonSerializerOptions.Converters.Add(new StringEnumConverter()); }) 我收到…

Asp.net Core 2.1记录 - c#

我想了解登录asp.net cortex 2.1的问题。我的目标是注册所有可能导致kestrel服务器损坏的严重错误。据我从文档中了解Microsoft.Extensions.Logging和Serilog,您需要在每个控制器中创建一个记录器,并设置记录条件(例如try / catch)。是否有一种更方便的方法可以从一个地方记录项目中的任何严重错误?我将不胜…