Startup.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Abp.AspNetCore;
  2. using Abp.AspNetCore.Mvc.Antiforgery;
  3. using Abp.AspNetCore.SignalR.Hubs;
  4. using Abp.Castle.Logging.Log4Net;
  5. using Abp.Dependency;
  6. using Abp.Json;
  7. using Castle.Facilities.Logging;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Newtonsoft.Json.Serialization;
  10. using VberAdmin.Authentication.JwtBearer;
  11. using VberAdmin.Configuration;
  12. using VberAdmin.Identity;
  13. using VberAdmin.Middleware;
  14. using VberAdmin.Resources;
  15. using VberZero.Workflows;
  16. namespace VberAdmin.Web.Startup;
  17. public class Startup
  18. {
  19. private readonly IWebHostEnvironment _hostingEnvironment;
  20. private readonly IConfigurationRoot _appConfiguration;
  21. public Startup(IWebHostEnvironment env)
  22. {
  23. _hostingEnvironment = env;
  24. _appConfiguration = env.GetAppConfiguration();
  25. }
  26. public IServiceProvider ConfigureServices(IServiceCollection services)
  27. {
  28. // MVC
  29. services.AddControllersWithViews(
  30. options =>
  31. {
  32. options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
  33. options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
  34. }
  35. )
  36. .AddRazorRuntimeCompilation()
  37. .AddNewtonsoftJson(options =>
  38. {
  39. options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance)
  40. {
  41. NamingStrategy = new CamelCaseNamingStrategy()
  42. };
  43. });
  44. IdentityRegistrar.Register(services);
  45. AuthConfigurer.Configure(services, _appConfiguration);
  46. // 自定义Cookie选项
  47. services.ConfigureCustomApplicationCookie(_appConfiguration);
  48. services.AddScoped<IWebResourceManager, WebResourceManager>();
  49. services.AddSignalR();
  50. //工作流
  51. //services.AddScoped<IVberPersistenceProvider, VbWorkflowPersistenceProvider>();
  52. services.ConfigVbWorkflow();
  53. // Configure Abp and Dependency Injection
  54. var serviceProvider = services.AddAbp<VberAdminWebMvcModule>(
  55. // Configure Log4Net logging
  56. options => options.IocManager.IocContainer.AddFacility<LoggingFacility>(
  57. f => f.UseAbpLog4Net().WithConfig(
  58. _hostingEnvironment.IsDevelopment()
  59. ? "log4net.config"
  60. : "log4net.Production.config"
  61. )
  62. )
  63. );
  64. return serviceProvider;
  65. }
  66. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
  67. {
  68. app.UseAbp(options =>
  69. {
  70. options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
  71. }); // Initializes ABP framework.
  72. //多语言本地化
  73. app.UseLocalizationCookieMiddleware();
  74. if (env.IsDevelopment())
  75. {
  76. app.UseDeveloperExceptionPage();
  77. }
  78. else
  79. {
  80. app.UseStatusCodePagesWithRedirects("~/Error?statusCode={0}");
  81. app.UseExceptionHandler("/Error");
  82. }
  83. app.UseHttpsRedirection();
  84. app.UseStaticFiles();
  85. app.UseRouting();
  86. app.UseAuthentication();
  87. app.UseJwtTokenMiddleware();
  88. app.UseAuthorization();
  89. app.UseEndpoints(endpoints =>
  90. {
  91. endpoints.MapHub<AbpCommonHub>("/signalr");
  92. endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
  93. endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
  94. });
  95. }
  96. }