I am learning ASP.NET Core Web API. I followed the tutorial and created an ASP.NET Core Web API project. but setting a static HTML page is not working.
This is my code:
WebApplicationBuilder 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(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "abc's API",
Description = "abc's Site directory API",
Version = "V1",
TermsOfService = new Uri("https://github.com/abc"),
Contact = new OpenApiContact
{
Name = "abc xyz",
Url = new Uri("https://github.com/abc")
},
License = new OpenApiLicense
{
Name = "Example License",
Url = new Uri("https://example.com/license")
}
});
// using System.Reflection;
string xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFilename);
options.IncludeXmlComments(xmlPath);
options.SchemaFilter<EnumSchemaFilter>();
});
builder.Services.Configure<AuthSetting>(builder.Configuration.GetRequiredSection(AuthSetting.AuthSection));
builder.Services.Configure<SPSetting>(builder.Configuration.GetRequiredSection(SPSetting.SPSection));
// Azure log system configuration, default location : D:\\home\\LogFiles\\Application
builder.Logging.AddAzureWebAppDiagnostics();
builder.Services.Configure<AzureFileLoggerOptions>(options =>
{
options.FileName = "azure-diagnostics-abc";
options.FileSizeLimit = 50 * 1024;
options.RetainedFileCountLimit = 5;
});
builder.Services.Configure<AzureBlobLoggerOptions>(options => { options.BlobName = "abc-log.txt"; });
WebApplication app = builder.Build();
// Configure the HTTP request pipeline.
app.UseDefaultFiles("/default.html");
app.UseStaticFiles();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = "abc";
});
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Basically, it's near to a newly created project. and I put the HTML page here:
Swagger and others all work well! but I cannot access to default HTML ("https://localhost:7184/default.html" is always 404)
Please help me!
