/
agontar
/
TOROS
Обзор
Документация
Войти
/
agontar
/
TOROS
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Webapplication_new/Program.cs
62 строки
2 KB
gav
add pgsql ef
18 сен 2024, 11:55
18 сен 2024, 11:55
d298696
Код
Авторство
О чём код?
using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using WebApplication1.Data; using WebApplication1.Models; using Microsoft.Extensions.Hosting.WindowsServices; // CancellationTokenSource cancelTokenSource = new System.Threading.CancellationTokenSource(); var options = new WebApplicationOptions { Args = args, ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default }; //private static CancellationTokenSource cancelTokenSource = new System.Threading.CancellationTokenSource(); var builder = WebApplication.CreateBuilder(options); //builder.WebHost.UseUrls("http://*:5003", "http://localhost:5284"); // Add services to the container. //var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); var connectionString = builder.Configuration.GetConnectionString("PgConnection"); builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseNpgsql(connectionString)); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores<ApplicationDbContext>(); builder.Services.AddControllersWithViews(); //builder.Services.AddSingleton<List<TreeViewNode>>(); builder.Host.UseWindowsService(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseMigrationsEndPoint(); } 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.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.MapRazorPages(); app.Run();