Startup.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Models.AccountModel.InitializeAccounts();
  26. //Models.ArticleModel.LoadArticles();
  27. }
  28. public IConfiguration Configuration { get; }
  29. // This method gets called by the runtime. Use this method to add services to the container.
  30. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  31. public void ConfigureServices(IServiceCollection services)
  32. {
  33. services.AddDbContext<ApplicationDbContext>(options =>
  34. options.UseMySQL(
  35. Configuration.GetConnectionString("DefaultConnection")));
  36. services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
  37. .AddEntityFrameworkStores<ApplicationDbContext>();
  38. services.AddRazorPages();
  39. services.AddServerSideBlazor();
  40. services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
  41. services.AddDatabaseDeveloperPageExceptionFilter();
  42. services.AddSingleton<WeatherForecastService>();
  43. services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
  44. }
  45. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  46. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  47. {
  48. if (env.IsDevelopment())
  49. {
  50. app.UseDeveloperExceptionPage();
  51. app.UseMigrationsEndPoint();
  52. }
  53. else
  54. {
  55. app.UseExceptionHandler("/Error");
  56. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  57. app.UseHsts();
  58. }
  59. app.UseHttpsRedirection();
  60. app.UseStaticFiles();
  61. //app.UseStaticFiles(new StaticFileOptions
  62. //{
  63. // ServeUnknownFileTypes = true
  64. //});
  65. app.UseRouting();
  66. app.UseMvcWithDefaultRoute();
  67. app.UseAuthentication();
  68. app.UseAuthorization();
  69. app.UseEndpoints(endpoints =>
  70. {
  71. endpoints.MapControllers();
  72. endpoints.MapBlazorHub();
  73. endpoints.MapFallbackToPage("/_Host");
  74. });
  75. }
  76. }
  77. }