| | |
| | | using Microsoft.AspNetCore.HttpsPolicy; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Mvc.Authorization; |
| | | using Microsoft.AspNetCore.StaticFiles; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Logging; |
| | | using Microsoft.OpenApi.Models; |
| | | using Newtonsoft.Json.Serialization; |
| | | using Quartz; |
| | | using Quartz.Impl; |
| | | using Quartz.Spi; |
| | | using Swashbuckle.AspNetCore.SwaggerUI; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | |
| | | { |
| | | op.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); |
| | | op.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; |
| | | // 返回数据首字母不小写,CamelCasePropertyNamesContractResolver是小写 |
| | | op.SerializerSettings.ContractResolver = new DefaultContractResolver(); |
| | | }); |
| | | //解决文档中首字母被小写的问题 |
| | | services.AddControllers().AddJsonOptions(config => |
| | | { |
| | | config.JsonSerializerOptions.PropertyNamingPolicy = null; |
| | | }); |
| | | #region Swagger 第二种方式 |
| | | services.AddSwaggerGen(c => |
| | | { |
| | | typeof(OpenApiGroup).GetEnumNames().ToList().ForEach(version => |
| | | { |
| | | |
| | | c.SwaggerDoc(version, new OpenApiInfo() |
| | | { |
| | | Title = $"新凯迪MesApi文档:{version}", |
| | | Version = version, |
| | | Description = $"Panda.Sewerage : {version} " |
| | | Description = $"Panda.Sewerage : {version} ", |
| | | }); |
| | | }); |
| | | |
| | | string basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location); |
| | | string xmlPath = Path.Combine(basePath, "VueWebCoreApi.xml"); |
| | | c.IncludeXmlComments(xmlPath, true); |
| | | }); |
| | | #endregion |
| | | |
| | | |
| | | // 设置配置 |
| | | AppSetting.SetAppSetting(Configuration.GetSection("ConnectionStrings")); |
| | | //log4net配置 |
| | |
| | | services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>(); |
| | | services.AddSingleton<IJobFactory, IOCJobFactory>(); |
| | | |
| | | |
| | | //跨域设置 |
| | | services.AddCors(options => |
| | | { |
| | |
| | | }); |
| | | //设置SignalR |
| | | services.AddSignalR(); |
| | | |
| | | |
| | | |
| | | //设置session,并设置超时时间 |
| | | services.AddSession(o => |
| | |
| | | services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); |
| | | |
| | | } |
| | | |
| | | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| | | public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLeftTime, ILoggerFactory loggerFactory) |
| | | { |
| | |
| | | { |
| | | DataOperator.SetConnectionString1(Convert.ToString(AppSetting.GetAppSetting("DBServer"))); |
| | | }); |
| | | |
| | | #region Swagger分组第二种 |
| | | app.UseSwagger(); |
| | | app.UseSwaggerUI(c => |
| | |
| | | { |
| | | c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"{version}"); |
| | | }); |
| | | |
| | | }); |
| | | #endregion |
| | | app.UseHttpsRedirection(); |
| | |
| | | app.UseRouting(); |
| | | |
| | | app.UseAuthorization(); |
| | | //添加静态文件中间件 |
| | | app.UseDefaultFiles(); |
| | | //添加授权文件 |
| | | app.UseStaticFiles(new StaticFileOptions() { |
| | | ContentTypeProvider = new FileExtensionContentTypeProvider() { |
| | | Mappings = { |
| | | [".xls"] = "application/vnd.ms-excel", |
| | | [".apk"] = "application/vnd.android.package-archive" |
| | | } |
| | | } |
| | | }); |
| | | app.UseStaticFiles(); |
| | | //跨域 |
| | | app.UseCors("cors"); |
| | | //用户session服务 |
| | |
| | | app.UseStaticHostEnviroment(); |
| | | //Quartz |
| | | app.UseQuartz(env).UseStaticHttpContext(); |
| | | //配置Excel下载 |
| | | //app.UseStaticFiles( |
| | | // new StaticFileOptions |
| | | // { |
| | | // //设置不限制content-type |
| | | // ServeUnknownFileTypes = true |
| | | // }); |
| | | //app.UseStaticFiles(new StaticFileOptions() |
| | | //{ |
| | | // ContentTypeProvider = new FileExtensionContentTypeProvider() |
| | | // { |
| | | // Mappings = { [".exe"] = "application/octect-stream" } |
| | | // } |
| | | //}); |
| | | |
| | | app.UseEndpoints(endpoints => |
| | | { |
| | | endpoints.MapControllers(); |
| | | endpoints.MapHub<ChatHub>("/ChatHub", options => |
| | | { |
| | | options.Transports = |
| | | HttpTransportType.WebSockets | |
| | | HttpTransportType.LongPolling; |
| | | HttpTransportType.WebSockets | |
| | | HttpTransportType.LongPolling; |
| | | }); |
| | | }); |
| | | loggerFactory.AddLog4Net("Config/log4net.config"); |