2021-04-30 14:52:42 +08:00
|
|
|
|
using Furion;
|
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
2021-04-30 14:52:42 +08:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
2021-04-30 14:52:42 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using Nirvana.Common;
|
2021-04-30 14:52:42 +08:00
|
|
|
|
using Serilog;
|
2021-09-30 09:27:59 +08:00
|
|
|
|
using System;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
using System.IO;
|
2022-03-28 17:19:48 +08:00
|
|
|
|
using System.Text;
|
2021-07-30 10:02:44 +08:00
|
|
|
|
using Waste.Core;
|
2021-04-30 14:52:42 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Waste.Web.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Startup : AppStartup
|
|
|
|
|
|
{
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
|
{
|
2021-09-30 09:27:59 +08:00
|
|
|
|
var configuration = App.Configuration;
|
2021-05-27 16:58:40 +08:00
|
|
|
|
services.AddSession();//使用Session
|
|
|
|
|
|
//services.AddJwt<JwtHandler>(options =>
|
|
|
|
|
|
//{
|
|
|
|
|
|
// options.DefaultScheme = null;
|
|
|
|
|
|
//});
|
|
|
|
|
|
services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
|
2021-04-30 14:52:42 +08:00
|
|
|
|
services.AddCorsAccessor();
|
2022-05-14 18:02:50 +08:00
|
|
|
|
services.AddRemoteRequest();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
services.AddHttpClient();
|
2021-09-30 09:27:59 +08:00
|
|
|
|
|
|
|
|
|
|
//添加CAP
|
2022-05-17 18:07:00 +08:00
|
|
|
|
string port = configuration["RabbitmqSetting:Port"];
|
|
|
|
|
|
int p = Convert.ToInt32(port);
|
|
|
|
|
|
if (p > 0)
|
2021-11-23 17:49:40 +08:00
|
|
|
|
{
|
2022-05-17 18:07:00 +08:00
|
|
|
|
services.AddCap(x =>
|
2021-11-23 17:49:40 +08:00
|
|
|
|
{
|
2022-05-17 18:07:00 +08:00
|
|
|
|
x.DefaultGroupName = "jtsky.queue.waste"; //rabbitmq的队列名称
|
|
|
|
|
|
//配置rabbitmq支持
|
|
|
|
|
|
x.UseRabbitMQ(opt =>
|
|
|
|
|
|
{
|
|
|
|
|
|
opt.HostName = configuration["RabbitmqSetting:HostName"]; //配置ip地址
|
|
|
|
|
|
opt.Port = p;//配置端口
|
|
|
|
|
|
opt.UserName = configuration["RabbitmqSetting:UserName"];//配置用户名
|
|
|
|
|
|
opt.Password = configuration["RabbitmqSetting:Password"];//配置Miami
|
|
|
|
|
|
});
|
|
|
|
|
|
//配置sqlserver支持
|
|
|
|
|
|
x.UseSqlServer(configuration["RabbitmqSetting:DBConnection"]);
|
2022-06-21 14:20:09 +08:00
|
|
|
|
x.SucceedMessageExpiredAfter = 3600;
|
2021-09-30 09:27:59 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2022-05-17 18:07:00 +08:00
|
|
|
|
}
|
2021-11-23 17:49:40 +08:00
|
|
|
|
services.AddControllers(options =>
|
|
|
|
|
|
{
|
2021-05-27 16:58:40 +08:00
|
|
|
|
options.EnableEndpointRouting = true;
|
|
|
|
|
|
})
|
2021-04-30 14:52:42 +08:00
|
|
|
|
.AddInjectWithUnifyResult<RESTfulResultProvider>();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
services.AddRazorPages(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
|
|
|
|
|
|
}).AddNewtonsoftJson(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; //日期格式化
|
|
|
|
|
|
options.SerializerSettings.ContractResolver = new CustomContractResolver();
|
|
|
|
|
|
});
|
|
|
|
|
|
services.AddSingleton<ITempDataProvider, CookieTempDataProvider>();
|
2021-06-02 15:10:40 +08:00
|
|
|
|
services.AddTaskScheduler();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
#region 注入获取IP
|
|
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
|
|
MyHttpContext.serviceCollection = services;
|
|
|
|
|
|
#endregion
|
2022-03-28 17:19:48 +08:00
|
|
|
|
//添加redis缓存
|
|
|
|
|
|
services.AddStackExchangeRedisCache(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// 连接字符串,这里也可以读取配置文件
|
|
|
|
|
|
options.Configuration = "localhost";
|
|
|
|
|
|
// 键名前缀
|
|
|
|
|
|
options.InstanceName = "jt_";
|
|
|
|
|
|
});
|
2021-08-11 08:16:16 +08:00
|
|
|
|
//添加即时通讯
|
2021-11-23 17:49:40 +08:00
|
|
|
|
// services.AddSignalR();
|
2021-04-30 14:52:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
|
{
|
2022-03-28 17:19:48 +08:00
|
|
|
|
//启用 GB2312(按需)
|
|
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
2021-05-27 16:58:40 +08:00
|
|
|
|
app.UseSession();
|
2021-04-30 14:52:42 +08:00
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
|
{
|
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-27 16:58:40 +08:00
|
|
|
|
// 添加规范化结果状态码,需要在这里注册
|
|
|
|
|
|
app.UseUnifyResultStatusCodes();
|
|
|
|
|
|
// 或者更多配置
|
|
|
|
|
|
// app.UseUnifyResultStatusCodes(options => { options.Return200StatusCodes = new [] { 401, 403 }; });
|
|
|
|
|
|
//允许body重用
|
|
|
|
|
|
app.Use(next => context =>
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Request.EnableBuffering();
|
|
|
|
|
|
return next(context);
|
|
|
|
|
|
});
|
2022-05-17 18:07:00 +08:00
|
|
|
|
// app.UseHttpsRedirection();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
|
|
|
|
|
|
app.UseStaticFiles();
|
2021-11-23 17:49:40 +08:00
|
|
|
|
app.UseSerilogRequestLogging(opts =>
|
|
|
|
|
|
{
|
2021-07-30 10:02:44 +08:00
|
|
|
|
opts.EnrichDiagnosticContext = LoggerHelper.EnrichFromRequest;
|
|
|
|
|
|
}); // 必须在 UseStaticFiles 和 UseRouting 之间,记录请求日志
|
2021-04-30 14:52:42 +08:00
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
|
|
app.UseCorsAccessor();
|
|
|
|
|
|
|
2021-11-23 17:49:40 +08:00
|
|
|
|
// app.UseAuthentication();
|
2021-04-30 14:52:42 +08:00
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
2021-05-27 16:58:40 +08:00
|
|
|
|
app.UseInject();
|
2021-04-30 14:52:42 +08:00
|
|
|
|
|
2021-08-11 08:16:16 +08:00
|
|
|
|
|
2021-04-30 14:52:42 +08:00
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
|
{
|
2021-08-11 08:16:16 +08:00
|
|
|
|
//注册集线器
|
2021-11-23 17:49:40 +08:00
|
|
|
|
// endpoints.MapHubs();
|
2021-05-27 16:58:40 +08:00
|
|
|
|
//endpoints.MapGet("/index.html", async context => {
|
|
|
|
|
|
// await context.Response.WriteAsync("Hello");
|
|
|
|
|
|
//});
|
|
|
|
|
|
endpoints.MapControllerRoute(
|
|
|
|
|
|
name: "default",
|
|
|
|
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
|
endpoints.MapRazorPages();
|
2021-04-30 14:52:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|