|
1 |
| -namespace IssuerDrivingLicense; |
| 1 | +using System.Configuration; |
| 2 | +using IssuerDrivingLicense; |
| 3 | +using IssuerDrivingLicense.Persistence; |
| 4 | +using Microsoft.AspNetCore.Authentication.OpenIdConnect; |
| 5 | +using Microsoft.AspNetCore.Server.Kestrel.Core; |
| 6 | +using Microsoft.EntityFrameworkCore; |
| 7 | +using Microsoft.Identity.Web.UI; |
| 8 | +using Microsoft.Identity.Web; |
2 | 9 |
|
3 |
| -public class Program |
| 10 | +var builder = WebApplication.CreateBuilder(args); |
| 11 | + |
| 12 | +builder.WebHost.ConfigureKestrel(serverOptions => |
| 13 | +{ |
| 14 | + serverOptions.AddServerHeader = false; |
| 15 | +}); |
| 16 | + |
| 17 | +var services = builder.Services; |
| 18 | +var configuration = builder.Configuration; |
| 19 | + |
| 20 | +services.Configure<KestrelServerOptions>(options => |
| 21 | +{ |
| 22 | + options.AllowSynchronousIO = true; |
| 23 | +}); |
| 24 | + |
| 25 | +services.AddSecurityHeaderPolicies() |
| 26 | + .SetPolicySelector(ctx => SecurityHeadersDefinitions |
| 27 | + .GetHeaderPolicyCollection(builder.Environment.IsDevelopment())); |
| 28 | + |
| 29 | +services.Configure<CredentialSettings>(configuration.GetSection("CredentialSettings")); |
| 30 | +services.AddScoped<DriverLicenseService>(); |
| 31 | +services.AddScoped<IssuerService>(); |
| 32 | + |
| 33 | +services.AddDatabaseDeveloperPageExceptionFilter(); |
| 34 | +services.AddDbContext<DrivingLicenseDbContext>(options => |
| 35 | + options.UseSqlServer( |
| 36 | + configuration.GetConnectionString("DefaultConnection"))); |
| 37 | + |
| 38 | +services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) |
| 39 | + .AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAd")); |
| 40 | + |
| 41 | +services.AddAuthorization(options => |
| 42 | +{ |
| 43 | + options.FallbackPolicy = options.DefaultPolicy; |
| 44 | +}); |
| 45 | + |
| 46 | +services.AddDistributedMemoryCache(); |
| 47 | + |
| 48 | +services.AddRazorPages() |
| 49 | + .AddMvcOptions(options => { }) |
| 50 | + .AddMicrosoftIdentityUI(); |
| 51 | + |
| 52 | +services.AddRazorPages(); |
| 53 | + |
| 54 | +var app = builder.Build(); |
| 55 | + |
| 56 | +app.UseSecurityHeaders(); |
| 57 | + |
| 58 | +if (app.Environment.IsDevelopment()) |
| 59 | +{ |
| 60 | + app.UseDeveloperExceptionPage(); |
| 61 | +} |
| 62 | +else |
4 | 63 | {
|
5 |
| - public static void Main(string[] args) |
6 |
| - { |
7 |
| - CreateHostBuilder(args).Build().Run(); |
8 |
| - } |
9 |
| - |
10 |
| - public static IHostBuilder CreateHostBuilder(string[] args) => |
11 |
| - Host.CreateDefaultBuilder(args) |
12 |
| - .ConfigureWebHostDefaults(webBuilder => |
13 |
| - { |
14 |
| - webBuilder |
15 |
| - .ConfigureKestrel(options => options.AddServerHeader = false) |
16 |
| - .UseStartup<Startup>(); |
17 |
| - }); |
| 64 | + app.UseExceptionHandler("/Error"); |
18 | 65 | }
|
| 66 | + |
| 67 | +app.UseHttpsRedirection(); |
| 68 | +app.UseStaticFiles(); |
| 69 | + |
| 70 | +app.UseRouting(); |
| 71 | + |
| 72 | +app.UseAuthentication(); |
| 73 | +app.UseAuthorization(); |
| 74 | + |
| 75 | +app.MapRazorPages(); |
| 76 | +app.MapControllers(); |
| 77 | + |
| 78 | +app.Run(); |
0 commit comments