Startup.cs 3.8 KB

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