从2.2升级到3后,ASP.Net Core身份验证不起作用

时间:2019-10-16 16:00:41

标签: c# asp.net-core asp.net-core-3.0

我在ASP.NET Core 2.2中有一个启用了身份验证的Web应用程序(类型MVC)(这是使用dotnet aspnet-codegenerator身份生成的)。一切都很好,直到那里。我必须将项目升级到ASP.Net Core 3.0,并且身份验证停止工作。 ¿有人可以帮我吗?

我认为我已经在documentation from 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中的调试中测试项目时,登录选项会导致: 本地主机/?area = Identity&page =%2FAccount%2FLogin

在迁移之前,它导致: 本地主机/身份/帐户/登录

如果我手动加载它,则会显示错误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>();
        });
    }
}

0 个答案:

没有答案
相关问题