|
using KH.WMS.Core.Monitoring.MiniProfiler;
|
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.Hosting;
|
|
namespace KH.WMS.Core.Setup;
|
|
/// <summary>
|
/// 中间件配置 - 统一入口
|
/// </summary>
|
public static class MiddlewareSetup
|
{
|
/// <summary>
|
/// 使用所有自定义中间件(按推荐顺序)
|
/// </summary>
|
/// <summary>
|
/// 使用所有自定义中间件(按推荐顺序)
|
/// </summary>
|
public static IApplicationBuilder UseCustomMiddleware(this IApplicationBuilder app, IWebHostEnvironment env)
|
{
|
// HTTPS 重定向(生产环境)
|
if (!env.IsDevelopment())
|
{
|
app.UseHttpsRedirection();
|
}
|
|
// 路由
|
app.UseRouting();
|
|
// 性能监控(在 UseRouting 之后)
|
app.UseMiniProfilerCustom();
|
|
// 认证
|
app.UseAuthentication();
|
|
// 授权
|
app.UseAuthorization();
|
|
// 端点映射
|
app.UseEndpoints(endpoints =>
|
{
|
endpoints.MapControllers();
|
endpoints.MapRazorPages(); // MiniProfiler UI 需要
|
});
|
|
return app;
|
}
|
|
}
|