Program.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Auth;
  2. var builder = WebApplication.CreateBuilder(args);
  3. // Add services to the container.
  4. builder.Services.AddControllersWithViews();
  5. // ÅäÖÿçÓò·ÃÎÊ
  6. var origins = builder.Configuration.GetSection("Cors:Origins").GetChildren().Select(x => x.Value ?? "").ToArray();
  7. builder.Services.AddCors(c =>
  8. {
  9. c.AddPolicy("cors", policy =>
  10. {
  11. policy.AllowAnyHeader();
  12. policy.AllowAnyMethod();
  13. policy.AllowCredentials();
  14. policy.WithOrigins(origins ?? Array.Empty<string>());
  15. });
  16. });
  17. // ÅäÖÃids4
  18. builder.Services.AddIdentityServer4Extension(builder.Configuration);
  19. var app = builder.Build();
  20. // Configure the HTTP request pipeline.
  21. if (!app.Environment.IsDevelopment())
  22. {
  23. app.UseExceptionHandler("/Home/Error");
  24. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  25. app.UseHsts();
  26. }
  27. app.UseHttpsRedirection();
  28. app.UseStaticFiles();
  29. app.UseRouting();
  30. app.UseCors("cors");
  31. app.UseIdentityServer();
  32. app.UseAuthorization();
  33. app.MapControllerRoute(
  34. name: "default",
  35. pattern: "{controller=Home}/{action=Index}/{id?}");
  36. app.Run();