c# - 从 2.2 升级到 3 后 ASP.Net Core 身份验证不起作用
问题描述
我在 ASP.NET Core 2.2 中有一个启用身份验证的 Web 应用程序(类型 MVC)(这是使用 dotnet aspnet-codegenerator 身份生成的)。一切都很好,直到那里。我不得不将项目升级到 ASP.Net Core 3.0 并且身份验证停止工作。有谁能够帮我 ?
我想我已经在Microsoft 的文档中提出了所描述的观点,但我不知道问题出在哪里。
项目参考:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="3.0.0" />
<PackageReference Include="RestSharp" Version="106.6.10" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="System.Linq.Queryable" Version="4.3.0" />
当我在 VS 中调试项目时,选项登录导致:localhost/?area=Identity&page=%2FAccount%2FLogin
在迁移之前,它导致:localhost/Identity/Account/Login
如果我手动加载它,它会给出错误 404
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<WalletContext>(item => item.UseSqlServer(Configuration.GetConnectionString("WalletConn")));
services.AddCloudscribePagination();
services.AddAuthentication();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "pagingMovements",
pattern: "pager/{p:int?}",
defaults: new { controller = "Movements", action = "Details" }
);
});
}
类 IdentityHostingStartup [程序集:HostingStartup(typeof(GLB.Wallet.Backoffice.Areas.Identity.IdentityHostingStartup))]
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDbContext<IdentityDataContext>(options =>
options.UseSqlServer(
context.Configuration.GetConnectionString("BackofficeConn")));
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<IdentityDataContext>();
});
}
}
解决方案
推荐阅读
- python - 如何在 python sounddevice 中使用 OutputStream 播放声音文件?
- scala - 无副作用的日志记录
- javascript - parse2升级javascript承诺问题
- gcc - 如何在 gcc 剥离期间保留符号?
- c - 如何读取 fseeked 的文件?
- javascript - Ajax 验证在 html 元素内重复 html 页面
- javascript - Gsap 无法与打字稿一起正常工作
- c++ - C ++中数组的大小是否灵活?
- python - 通过pandas列按字符串选择行(有条件)
- python - 具有无法识别的时间格式的 Pandas MultiIndex - 如何转换时间和应用计算