Startup.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. using Console = HyperCube.Utils.AdvConsole;
  19. namespace HyperCube
  20. {
  21. public class Startup
  22. {
  23. public Startup(IConfiguration configuration)
  24. {
  25. Configuration = configuration;
  26. Models.AccountModel.InitializeAccounts();
  27. try
  28. {
  29. Console.WriteLine("OnInitializedAsync RegisterNetworks");
  30. Models.Blockchain.RegisterNetworks();
  31. }
  32. catch (Exception e)
  33. {
  34. Console.WriteLine(e.Message + ", stack trace:" + e.StackTrace);
  35. }
  36. Console.WriteLine($"Paths, app: [{AppDomain.CurrentDomain.BaseDirectory}], working: [{Environment.CurrentDirectory}]");
  37. }
  38. public IConfiguration Configuration { get; }
  39. // This method gets called by the runtime. Use this method to add services to the container.
  40. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  41. public void ConfigureServices(IServiceCollection services)
  42. {
  43. services.AddDbContext<ApplicationDbContext>(options =>
  44. options.UseMySQL(
  45. Configuration.GetConnectionString("DefaultConnection")));
  46. services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
  47. .AddRoles<IdentityRole>()
  48. .AddEntityFrameworkStores<ApplicationDbContext>();
  49. services.AddRazorPages();
  50. services.AddServerSideBlazor();
  51. services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
  52. services.AddDatabaseDeveloperPageExceptionFilter();
  53. services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
  54. services.AddScoped<AppData>();
  55. }
  56. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  57. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  58. {
  59. if (env.IsDevelopment())
  60. {
  61. app.UseDeveloperExceptionPage();
  62. app.UseMigrationsEndPoint();
  63. }
  64. else
  65. {
  66. app.UseExceptionHandler("/Error");
  67. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  68. app.UseHsts();
  69. }
  70. app.UseHttpsRedirection();
  71. app.UseStaticFiles();
  72. //app.UseStaticFiles(new StaticFileOptions
  73. //{
  74. // ServeUnknownFileTypes = true
  75. //});
  76. app.UseRouting();
  77. app.UseMvcWithDefaultRoute();
  78. app.UseAuthentication();
  79. app.UseAuthorization();
  80. app.UseEndpoints(endpoints =>
  81. {
  82. endpoints.MapControllers();
  83. endpoints.MapBlazorHub();
  84. endpoints.MapFallbackToPage("/_Host");
  85. });
  86. }
  87. }
  88. }