Startup.cs 3.2 KB

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