Startup.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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:\r\nApp:{AppDomain.CurrentDomain.BaseDirectory}\r\nWorking: {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. .AddEntityFrameworkStores<ApplicationDbContext>();
  48. services.AddRazorPages();
  49. services.AddServerSideBlazor();
  50. services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
  51. services.AddDatabaseDeveloperPageExceptionFilter();
  52. services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
  53. services.AddScoped<AppData>();
  54. }
  55. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  56. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  57. {
  58. if (env.IsDevelopment())
  59. {
  60. app.UseDeveloperExceptionPage();
  61. app.UseMigrationsEndPoint();
  62. }
  63. else
  64. {
  65. app.UseExceptionHandler("/Error");
  66. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  67. app.UseHsts();
  68. }
  69. app.UseHttpsRedirection();
  70. app.UseStaticFiles();
  71. //app.UseStaticFiles(new StaticFileOptions
  72. //{
  73. // ServeUnknownFileTypes = true
  74. //});
  75. app.UseRouting();
  76. app.UseMvcWithDefaultRoute();
  77. app.UseAuthentication();
  78. app.UseAuthorization();
  79. app.UseEndpoints(endpoints =>
  80. {
  81. endpoints.MapControllers();
  82. endpoints.MapBlazorHub();
  83. endpoints.MapFallbackToPage("/_Host");
  84. });
  85. }
  86. }
  87. }