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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
namespace LaunchUrlStudy.SubSite2
{
public class Program
{
public static void Main ( string [ ] args )
{
var builder = WebApplication . CreateBuilder ( args ) ;
builder . Services . AddControllers ( ) ;
builder . Services . AddEndpointsApiExplorer ( ) ;
builder . Services . AddSwaggerGen ( ) ;
var app = builder . Build ( ) ;
app . UseSwagger ( ) ;
app . UseSwaggerUI ( ) ;
app . UseAuthorization ( ) ;
app . MapControllers ( ) ;
//配置启动地址(支持子站点):路由+自定义内容
app . MapGet ( "/" , async context = >
{
//绝对Url
string swaggerUrl = Microsoft . AspNetCore . Http . Extensions . UriHelper . BuildAbsolute ( context . Request . Scheme , context . Request . Host , context . Request . PathBase , "/swagger/index.html" ) ;
//相对Url
string swaggerUrl2 = Microsoft . AspNetCore . Http . Extensions . UriHelper . BuildRelative ( context . Request . PathBase , "/swagger/index.html" ) ;
context . Response . ContentType = "text/html" ;
var wellcomHtml =
$"""
<!DOCTYPE html>
<html lang=" zh - CN ">
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title > { AppDomain . CurrentDomain . FriendlyName } < / title >
< / head >
< body >
< div style = "text-align:center" >
< h2 > { AppDomain . CurrentDomain . FriendlyName } 启 动 成 功 ! < / h2 >
< h3 > 详 情 参 阅 : < a href = "{swaggerUrl}" > Swagger 文 档 < / a > < / h3 >
< / div >
< / body >
< / html >
"" ";
await context . Response . WriteAsync ( wellcomHtml ) ;
} ) ;
app . Run ( ) ;
}
}
}