| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using Abp.AspNetCore;
- using Abp.AspNetCore.Mvc.Antiforgery;
- using Abp.AspNetCore.SignalR.Hubs;
- using Abp.Castle.Logging.Log4Net;
- using Abp.Dependency;
- using Abp.Json;
- using Castle.Facilities.Logging;
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json.Serialization;
- using VberAdmin.Authentication.JwtBearer;
- using VberAdmin.Configuration;
- using VberAdmin.Identity;
- using VberAdmin.Middleware;
- using VberAdmin.Resources;
- using VberZero.Workflows;
- namespace VberAdmin.Web.Startup;
- public class Startup
- {
- private readonly IWebHostEnvironment _hostingEnvironment;
- private readonly IConfigurationRoot _appConfiguration;
- public Startup(IWebHostEnvironment env)
- {
- _hostingEnvironment = env;
- _appConfiguration = env.GetAppConfiguration();
- }
- public IServiceProvider ConfigureServices(IServiceCollection services)
- {
- // MVC
- services.AddControllersWithViews(
- options =>
- {
- options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
- options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
- }
- )
- .AddRazorRuntimeCompilation()
- .AddNewtonsoftJson(options =>
- {
- options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance)
- {
- NamingStrategy = new CamelCaseNamingStrategy()
- };
- });
- IdentityRegistrar.Register(services);
- AuthConfigurer.Configure(services, _appConfiguration);
- // 自定义Cookie选项
- services.ConfigureCustomApplicationCookie(_appConfiguration);
- services.AddScoped<IWebResourceManager, WebResourceManager>();
- services.AddSignalR();
- //工作流
- //services.AddScoped<IVberPersistenceProvider, VbWorkflowPersistenceProvider>();
- services.ConfigVbWorkflow();
- // Configure Abp and Dependency Injection
- var serviceProvider = services.AddAbp<VberAdminWebMvcModule>(
- // Configure Log4Net logging
- options => options.IocManager.IocContainer.AddFacility<LoggingFacility>(
- f => f.UseAbpLog4Net().WithConfig(
- _hostingEnvironment.IsDevelopment()
- ? "log4net.config"
- : "log4net.Production.config"
- )
- )
- );
- return serviceProvider;
- }
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
- {
- app.UseAbp(options =>
- {
- options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
- }); // Initializes ABP framework.
- //多语言本地化
- app.UseLocalizationCookieMiddleware();
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseStatusCodePagesWithRedirects("~/Error?statusCode={0}");
- app.UseExceptionHandler("/Error");
- }
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseRouting();
- app.UseAuthentication();
- app.UseJwtTokenMiddleware();
- app.UseAuthorization();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapHub<AbpCommonHub>("/signalr");
- endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
- endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
- });
- }
- }
|