ASP.NET Core 2 MVC Identity不支持共享主机

时间:2018-05-31 12:31:17

标签: asp.net-identity shared-hosting

我意外退出了用户。有人知道它是否与应用程序池或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();
}

0 个答案:

没有答案