When I publish my ASP.NET Core 8 Minimal API project using these settings:
Configuration: Release
Target framework: net8.0
Target runtime: Portable
on IIS on a Windows Server 2012 R2, I always get 404 errors.
To test if IIS is actually serving something, I have created an index.html in the root of the website. When I browse to this location the index.html is served. So IIS does serve something...
I have also installed the ASP.NET Core Runtime 8.0.5 Windows Hosting Bundle.
In IIS I have an ApplicationPool with these settings:
- .NET CLR Version v4.0.30319
- Pipeline Mode: Integrated
According to several resources on the web this should do the trick. But in my case however I keep getting 404 errors, no matter what.
- When accessing
/swagger-> 404 (and yes I did remove theIsDevelopment()check :)) - When accessing a GET request (
/foo/1) I get a 404
What am I missing or what can I do to troubleshoot this further?
PS: I have full control over the Windows server.
Here's my program.cs:
using MediatR;
using ProjectLifeApi.Application.CreateToDoItem;
using ProjectLifeApi.Application.GetToDoItems;
using ProjectLifeApi.Infrastructure;
using ProjectLifeApi.Infrastructure.CreateTask;
using ProjectLifeApi.Infrastructure.GetToDoItems;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.CustomSchemaIds(type => type.ToString());
});
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<SqlSaveToDoItem>());
builder.Services.AddTransient<ISaveToDoItem, SqlSaveToDoItem>();
builder.Services.AddTransient<IGetToDoItems, SqlGetToDoItems>();
var dbSettings = new DatabaseSettings();
builder.Configuration.GetSection("Database").Bind(dbSettings);
builder.Services.AddSingleton<DatabaseSettings>(dbSettings);
var app = builder.Build();
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
app.UseSwagger();
app.UseSwaggerUI();
//}
//app.UseHttpsRedirection();
app.MapPost("/todo", async (CreateToDoItemCommand command, ISender sender) =>
{
await sender.Send(command);
});
app.MapGet("/todo/{date}", async (DateOnly date, ISender sender) =>
{
return await sender.Send(new GetToDoItemsQuery { Date = date });
});
app.Run();