您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Startup.cs 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.HttpsPolicy;
  4. using Microsoft.AspNetCore.Identity;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using MVCTemplate.Business.Infrastructure;
  9. using MVCTemplate.Business.Infrastructure.Extensions;
  10. using MVCTemplate.Business.Infrastructure.Settings;
  11. using MVCTemplate.Data.DbContexts;
  12. using MVCTemplate.Infrastructure.Middleware;
  13. namespace MVCTemplate
  14. {
  15. public class Startup
  16. {
  17. public Startup(IConfiguration configuration)
  18. {
  19. Configuration = configuration;
  20. }
  21. public IConfiguration Configuration { get; }
  22. // This method gets called by the runtime. Use this method to add services to the container.
  23. public void ConfigureServices(IServiceCollection services)
  24. {
  25. StartupConfiguration.ConfigureStartupConfig<EmailSettings>(services, Configuration);
  26. services.AddControllersWithViews();
  27. services.AddRazorPages();
  28. StartupExtensions.ConfigureServices(services);
  29. services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
  30. .AddDefaultUI()
  31. .AddRoles<IdentityRole>()
  32. .AddEntityFrameworkStores<AppDbContext>();
  33. }
  34. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  35. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  36. {
  37. if (env.IsDevelopment())
  38. {
  39. app.UseDeveloperExceptionPage();
  40. }
  41. else
  42. {
  43. app.UseExceptionHandler("/Home/Error");
  44. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  45. app.UseHsts();
  46. }
  47. app.UseHttpsRedirection();
  48. app.UseStaticFiles();
  49. app.UseRouting();
  50. app.UseAuthentication();
  51. app.UseAuthorization();
  52. app.UseMiddleware(typeof(ExceptionHandlingMiddleware));
  53. app.UseEndpoints(endpoints =>
  54. {
  55. endpoints.MapControllerRoute(
  56. name: "default",
  57. pattern: "{controller=Home}/{action=Index}/{id?}");
  58. endpoints.MapRazorPages();
  59. });
  60. }
  61. }
  62. }