You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
|
|
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();
|
|
}
|
|
}
|
|
}
|