我正在按照一个示例在 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”的参数(您是否一团糟 using指令还是程序集引用?)
我在做什么错了?
答案 0 :(得分:1)
使用
app.UseAuthentication();
对我有用
答案 1 :(得分:0)
文档说,自ASP.NET Core 2.2起,UseIdentity
已过时,应改为使用UseAuthentication
此方法已过时,将在以后的版本中删除。推荐的替代方法是
UseAuthentication(IApplicationBuilder)