I already have been trying to solve this for days, I created a Web API application (using .NET 5, VS2019) and when I was finally be able to run it without errors in the IIS, I receive 404 errors in the responses, simply put the controller code is never called (never hit by the debugger) with no exceptions or any other errors, just this screen (calling the first route in the controller):
This localhost page can’t be found No webpage was found for the web address:
https://localhost:44342/sicrestweb/sync/gs/usuarios?json_data={fields:*,%20database:"Provider=Microsoft.ACE.OLEDB.12.0;Data%20Source=F:\VBDev\Sicrest3.4\DPWT314.mdb;%20Persist%20Security%20Info=False;"}
Here is the Program code:
public static void Main(string[] args)
{
CD = Directory.GetCurrentDirectory();
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
The Startup code:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddScoped<ISyncService, SyncService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); }
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
}
The controller code (fragment) :
[ApiController]
[Route("SicrestWeb/[controller]")]
public class SyncController : ControllerBase // Controller
{
private readonly ISyncService ISS;
private SyncService SS { get { return (SyncService) ISS; } }
public ActionResult HTTPResponse { get { return SS.HTTPResponse; } } // HTTP Response
public String CurrentRoute { get { return (Request != null && Request.Path != null) ? (Request.Path.Value ?? TestRoute) :TestRoute; } } // Get route string
public String TestRoute { get; set; }
public SyncController(ISyncService isys) { ISS = isys; TestRoute = ""; }
[HttpGet]
[Route("GS/{table_name}/{json_data}/{key=''}")]
[Route("GSI/{table_name}/{json_data}/{key=''}")]
public ActionResult Select(String table_name, String json_data, String key="") // (GS) returns data as requested
{
// process request
if (!ISS.Dispatch(CurrentRoute, table_name, json_data, key))
{
// Handles error
}
// Generate response
return HTTPResponse;
}
. . . }
The only things I am sure is the controller code works when is called directly (it is already unit tested), but the address/routing mechanism never calls it, like the controller and its routes are not identified thus are never called.