using Microsoft.AspNetCore.Http.Extensions; namespace LaunchUrlStudy.SubSite4 { public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); app.UseSwagger(); app.UseSwaggerUI(); app.UseAuthorization(); app.MapControllers(); //配置启动地址(支持子站点):自定义中间件+重定向 app.Use(async (context, next) => { if (context.Request.Path == "" || context.Request.Path == "/") { string swaggerUrl = UriHelper.BuildAbsolute(context.Request.Scheme, context.Request.Host, context.Request.PathBase, "/swagger"); context.Response.Redirect(swaggerUrl); } else { await next(); } }); app.Run(); } } }