.net swagger的API项目里面 同时可以运行wwwroot里面的网页
在Program.cs里面添加一行:
app.UseStaticFiles();//使用静态网页
完整的 Program.cs
var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();var app = builder.Build();app.UseStaticFiles();//启用wwwroot里面的静态网页// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{app.UseSwagger();app.UseSwaggerUI();
}app.UseHttpsRedirection();app.UseAuthorization();app.MapControllers();app.Run();
项目根目录创建wwwroor文件夹
wwwroor文件夹里面创建index.html文件
Swagger的API地址:https://localhost:7014/swagger/index.html
wwwroor的静态网页:https://localhost:7014/index.html