85 lines
2.2 KiB
C#
85 lines
2.2 KiB
C#
|
|
using Furion;
|
|||
|
|
using Microsoft.AspNetCore.DataProtection;
|
|||
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Nirvana.Common;
|
|||
|
|
using Serilog;
|
|||
|
|
using System.Text;
|
|||
|
|
using Microsoft.AspNetCore.Builder;
|
|||
|
|
using Microsoft.AspNetCore.Hosting;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
|
using Microsoft.Extensions.Hosting;
|
|||
|
|
using Furion.DependencyInjection;
|
|||
|
|
using System;
|
|||
|
|
using Waste.Domain;
|
|||
|
|
|
|||
|
|
namespace Waste.OpenApi.Host
|
|||
|
|
{
|
|||
|
|
public class Startup// : AppStartup
|
|||
|
|
{
|
|||
|
|
public void ConfigureServices(IServiceCollection services)
|
|||
|
|
{
|
|||
|
|
var configuration = App.Configuration;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
services.AddControllers(options =>
|
|||
|
|
{
|
|||
|
|
options.EnableEndpointRouting = true;
|
|||
|
|
}).AddInject();
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region 注入获取IP
|
|||
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|||
|
|
MyHttpContext.serviceCollection = services;
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|||
|
|
{
|
|||
|
|
//启用 GB2312(按需)
|
|||
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|||
|
|
if (env.IsDevelopment())
|
|||
|
|
{
|
|||
|
|
app.UseDeveloperExceptionPage();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 或者更多配置
|
|||
|
|
// app.UseUnifyResultStatusCodes(options => { options.Return200StatusCodes = new [] { 401, 403 }; });
|
|||
|
|
//允许body重用
|
|||
|
|
app.Use(next => context =>
|
|||
|
|
{
|
|||
|
|
context.Request.EnableBuffering();
|
|||
|
|
return next(context);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
app.UseStaticFiles();
|
|||
|
|
// 必须在 UseStaticFiles 和 UseRouting 之间,记录请求日志
|
|||
|
|
app.UseRouting();
|
|||
|
|
|
|||
|
|
|
|||
|
|
// app.UseAuthentication();
|
|||
|
|
app.UseAuthorization();
|
|||
|
|
|
|||
|
|
app.UseInject();
|
|||
|
|
|
|||
|
|
|
|||
|
|
app.UseEndpoints(endpoints =>
|
|||
|
|
{
|
|||
|
|
endpoints.MapControllerRoute(
|
|||
|
|
name: "default",
|
|||
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class CurrentUser : ICurrentUser, ITransient
|
|||
|
|
{
|
|||
|
|
public Guid? Id => null;
|
|||
|
|
}
|
|||
|
|
}
|