ASP.NET Core 2 MVC Identity не работает на виртуальном хостинге - PullRequest
0 голосов
/ 31 мая 2018

У меня неожиданный выход пользователя из системы.Кто-нибудь знает, связано ли это с пулом приложений или файлами cookie?Я пытался настроить проблему, но пока не знаю, какое направление выбрать.Локально все было хорошо.

Вот мой стартап:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<GanDrorIdentityDb>(options =>
             options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("GanDror")));

    services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<GanDrorIdentityDb>()
            .AddDefaultTokenProviders();

    services.Configure<SMPTConfig>(Configuration.GetSection("SMTPConfigSection"));

    // Configure Identity
    services.Configure<IdentityOptions>(identityOptions =>
    {             
        // Password settings
        identityOptions.Password.RequireDigit = true;
        identityOptions.Password.RequiredLength = 6;
        identityOptions.Password.RequireNonAlphanumeric = false;
        identityOptions.Password.RequireUppercase = false;
        identityOptions.Password.RequireLowercase = false;

        // Lockout settings
        identityOptions.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
        identityOptions.Lockout.MaxFailedAccessAttempts = 10;

        // User settings
        identityOptions.User.RequireUniqueEmail = true; 
    });

    // Cookie settings
    services.ConfigureApplicationCookie(options =>
    {
        options.Cookie.SameSite = SameSiteMode.Strict;
        // Cookie settings
        options.Cookie.HttpOnly = true;
        options.ExpireTimeSpan = TimeSpan.FromDays(100);
        options.LoginPath = new PathString("/Account/Login");
        options.LogoutPath = new PathString("/Account/LogOut");
        .options.AccessDeniedPath = "/Account/AccessDenied";
        options.SlidingExpiration = true;
        options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
        options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
    });

    //var environment = services.BuildServiceProvider().GetRequiredService<IHostingEnvironment>();

    //services.AddDataProtection()
    //        .SetApplicationName($"my-app-{environment.EnvironmentName}")
    //        .PersistKeysToFileSystem(new System.IO.DirectoryInfo($@"{environment.ContentRootPath}\keys"));

    //  services.AddDataProtection();
    services.AddMvc();

    services.Configure<MvcOptions>(options =>
    {
        options.Filters.Add(new RequireHttpsAttribute());
    });

    // Add application services.
    services.AddScoped<IRepository<User>, UserRepository>();
    services.AddScoped<IRepository<Photo>, PhotoRepository>();
    services.AddScoped<IRepository<GanActivity>, ActivityRepository>();
    services.AddScoped<IRepository<CategoryActivity>, CategoryRepository>();
    services.AddSingleton<IEmailSender, EmailSender>();   
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public  void Configure(IApplicationBuilder app, IHostingEnvironment env,IServiceProvider serviceProvider, ILoggerFactory loggerFactory)// RoleManager<ApplicationRole> roleManager, UserManager<ApplicationUser> userManager)
{
    // loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    //loggerFactory.AddDebug();

    if (env.IsDevelopment())       
    {
        app.UseBrowserLink();
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
    }

    var options = new RewriteOptions()
        .AddRedirectToHttps();

    app.UseRewriter(options);
    app.UseStaticFiles();

    app.UseAuthentication();

    app.UseMvcWithDefaultRoute();
    //app.UseMvc(routes =>
    //{
    //    routes.MapRoute(
    //        name: "default",
    //        template: "{controller=Home}/{action=Index}/{id?}");
    //});

    CreateRoles(serviceProvider).Wait();
}
...