using ConstructorApp.BusinessLayer.Abstract; using ConstructorApp.BusinessLayer.Concrete; using ConstructorApp.DataAccessLayer.Abstract; using ConstructorApp.DataAccessLayer.Concrete; using ConstructorApp.DataAccessLayer.EntityFramework; using ConstructorApp.EntityLayer.Entities; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc.Authorization; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); //Proje seviyesinde Authenticationı var requireAuthorizePolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); // Add services to the container. builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("mssql"))); // IFooterService ve FooterService servisini ekleyin builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); builder.Services.AddHttpClient(); //Tüm projede kullanıcıları login olmaya zorla builder.Services.AddControllersWithViews(opt => { opt.Filters.Add(new AuthorizeFilter(requireAuthorizePolicy)); }); //Login sayfasını default olan Account/Login yerine kendi login sayfama yönlendir builder.Services.ConfigureApplicationCookie(opts => { opts.LoginPath = "/Login/Index/"; }); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseAuthentication(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run();