А в launchessettings выставляешь соответствующий DOTNET_ENVIRONMENT.
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.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapControllerRoute(
// name: "default",
// pattern: "{controller=Home}/{action=Index}/{id?}");
// endpoints.MapRazorPages();
//});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "area",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=HomeUser}/{action=Index}/{id?}");
});
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
.UseLazyLoadingProxies());
services.ConfigureApplicationCookie(options =>
{
options.Events.OnRedirectToLogin = context =>
{
context.Response.StatusCode = 401;
return Task.CompletedTask;
};
});
services.AddAuthentication(options => options.DefaultScheme = "Cookies")
.AddCookie("Cookies", "Cookies", options => {
options.Events.OnRedirectToAccessDenied = context =>
{
context.Response.StatusCode = 403;
return Task.CompletedTask;
};
});
//services.AddIdentity(options => options.SignIn.RequireConfirmedAccount = false)
// .AddEntityFrameworkStores()
// .AddDefaultTokenProviders()
// .AddDefaultUI();
services.AddSession();
services.AddMvc(option => option.EnableEndpointRouting = false);
// .AddJsonOptions(x => x.JsonSerializerOptions.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); ;
//services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true)
// .AddEntityFrameworkStores();
services.AddControllersWithViews();
services.AddRazorPages();
// настройки сессии
services.AddHttpContextAccessor();
// настройка работы с сессией
// https://docs.microsoft.com/ru-ru/aspnet/core/funda...
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
}