ASP.Net Core Identity Pages部署到服务器后会引发404错误,但可以在本地IIS中正常托管

时间:2020-05-28 07:51:12

标签: asp.net-mvc asp.net-core .net-core asp.net-identity

在将项目托管在本地IIS和服务器中之后,我发现在服务器中所有与身份相关的页面均会引发404错误,而在本地IIS中则可以正常工作。除身份页面以外的所有其他页面均可访问。我的StartUp类如下:

公共类启动 { 公共启动(IConfiguration配置) { 配置=配置; }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    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 => false;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });


        services.AddSingleton<IFileProvider>(
        new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")));


        var connectionString = this.Configuration.GetConnectionString("DefaultConnection");
        services.AddDbContext<ApplicationDbContext>(options =>
        {
            options.UseSqlServer(connectionString);
            options.UseLazyLoadingProxies(true);

        });
        //services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

        services.AddDefaultIdentity<XonetPlus_V3.Entities.Domain.User>(options => options.SignIn.RequireConfirmedAccount = false)
        .AddRoles<IdentityRole>().AddDefaultUI()
        .AddEntityFrameworkStores<ApplicationDbContext>();




        services.AddDataProtection()
 .PersistKeysToFileSystem(new DirectoryInfo(@"c:\shared-auth-ticket-keys\"))
 .SetApplicationName("SharedCookieApp");

        services.ConfigureApplicationCookie(options => {
            options.Cookie.Name = ".AspNet.SharedCookie";
        });



        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
        services.AddTransient<IRepositoryWrapper, RepositoryWrapper>();
        services.AddScoped<IEmailSender, EmailSender>();
    }


    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager<User> userManager, RoleManager<IdentityRole> roleManager)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseCookiePolicy();
        app.UseRouting();
        app.UseAuthentication();
        IdentityDataInitializer.SeedData(userManager, roleManager);
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute("default", "{controller=admindashboard}/{action=Index}/{id?}");
            // endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapControllerRoute("queryParams", "{controller=admindashboard}/{action=Index}/{param}/{id}");
            endpoints.MapControllerRoute("areas", "{area:exists}/{controller=admindashboard}/{action=Index}");
            endpoints.MapRazorPages();
        });

    }
}

0 个答案:

没有答案