c# - 我将 .NET CORE 项目从 2.1 更新到 3.1,但在 Startup 类中出现了一些错误
问题描述
我刚刚更新了我的 .NET CORE 版本。我已经更新了所有使用,但是在添加默认标识时,在方法 ConfigureServices 中的 satrtup 类中仍然存在错误。它只是给我一个错误,说“'IServiceCollection' 不包含'AddDefaultIdentity 的定义并且没有可访问的扩展方法'AddDefaultIdentity ...'”。这是方法:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
//ERROR
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
//SIGNAL R
services.AddSignalR();
}
我在 Configure 方法中也有错误。
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//ERROR
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
//MORE CODE
}
我应该怎么做才能解决这个错误?
解决方案
这两个扩展方法已移动到单独的 NuGet 包中,必须在 ASP.NET Core 3.0 及更高版本中显式引用:
方法 | 包裹 |
---|---|
AddDefaultIdentity |
Microsoft.AspNetCore.Identity.UI |
UseDatabaseErrorPage |
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore |
推荐阅读
- excel - 如何在 VBA 中的 IF 语句中的 Match 语句中对 2 个部分文本(一个或另一个)使用 OR 语句?
- arrays - MongoDB 在具有多个嵌套级别的数组和对象中查找
- bash - bash 脚本中 =<(...) 的语法
- selenium - 您可以在 Cucumber 功能“示例:”部分中使用外部资源吗?
- ios - 原生 ios webview 上的 Webrtc 支持
- hadoop - Hadoop 3.3 和 oozie 5.2.0
- scikit-learn - 我不明白在训练测试拆分和 MLP 回归器中更改随机状态之间的区别
- docker - 使用入口点执行脚本后将数据从容器复制到主机
- java - 使用 mTLS 和 WSS 时提取客户端证书信息
- javascript - 公开全局 API 方法来控制 vue 组件