Startup.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using HyperCube.Areas.Identity;
  2. using HyperCube.Data;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Components;
  5. using Microsoft.AspNetCore.Components.Authorization;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.HttpsPolicy;
  8. using Microsoft.AspNetCore.Identity;
  9. using Microsoft.AspNetCore.Identity.UI;
  10. using Microsoft.EntityFrameworkCore;
  11. using Microsoft.Extensions.Configuration;
  12. using Microsoft.Extensions.DependencyInjection;
  13. using Microsoft.Extensions.Hosting;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Threading.Tasks;
  18. namespace HyperCube
  19. {
  20. public class Startup
  21. {
  22. public Startup(IConfiguration configuration)
  23. {
  24. Configuration = configuration;
  25. }
  26. public IConfiguration Configuration { get; }
  27. // This method gets called by the runtime. Use this method to add services to the container.
  28. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddDbContext<ApplicationDbContext>(options =>
  32. options.UseMySQL(
  33. Configuration.GetConnectionString("DefaultConnection")));
  34. services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
  35. .AddEntityFrameworkStores<ApplicationDbContext>();
  36. services.AddRazorPages();
  37. services.AddServerSideBlazor();
  38. services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
  39. services.AddDatabaseDeveloperPageExceptionFilter();
  40. services.AddSingleton<WeatherForecastService>();
  41. }
  42. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  43. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  44. {
  45. if (env.IsDevelopment())
  46. {
  47. app.UseDeveloperExceptionPage();
  48. app.UseMigrationsEndPoint();
  49. }
  50. else
  51. {
  52. app.UseExceptionHandler("/Error");
  53. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  54. app.UseHsts();
  55. }
  56. app.UseHttpsRedirection();
  57. app.UseStaticFiles();
  58. //app.UseStaticFiles(new StaticFileOptions
  59. //{
  60. // ServeUnknownFileTypes = true
  61. //});
  62. app.UseRouting();
  63. app.UseAuthentication();
  64. app.UseAuthorization();
  65. app.UseEndpoints(endpoints =>
  66. {
  67. endpoints.MapControllers();
  68. endpoints.MapBlazorHub();
  69. endpoints.MapFallbackToPage("/_Host");
  70. });
  71. }
  72. }
  73. }