1. First, check if you have uploaded all necessary files of your API site to the server.
We recommend using Web Deploy to publish your application, this will package your app to production files and upload them to the destination server.
2. Second, if the publish progress went smoothly, but you still receive error 404.
Please check the Startup.cs (.net core version lower than 6.0) or Program.cs (.net core version 6.0), make sure you have registered the Controller middleware properly and configured correct route for the API endpoint.
Startup.cs
public class Startup
{
...
...
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
...
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
...
...
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Program.cs
...
builder.Services.AddControllers();
...
...
app.MapControllers();
app.Run();
API Endpoint
// these settings can be customized
[Route("api/[controller]")]
[ApiController]
[HttpGet]
3. Third, all API endpoints work properly, but the Swagger docs(/swagger/index.html) link returns error 404, it works on your local but on server does not.
The OpenAPI support will be placed in development code snippets default, it only takes effect in the development environment, while the server default environment is production.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
To make the Swagger docs work in a production server, you can move the above code snippets outside of the if judgment.
4. After you finish the above, please republish your API app to the server through Web Deploy and retry. If you still get an error when browsing the production site, you can enable the logging system of ASP.NET Core to diagnose.
5. Please feel free to contact our support if you need assistance.