The same Web API Code works on Windows 10 but not on Linux Debian Buster

  .net-core, api-design, c++, linux, windows

In the screenshot below, i have my Web API running with .NET5.0 on Windows 10 (left) and the same Web API running with .NET(core?)5.0 on Linux Debian Buster (right) (WSL2).

Pìcture showing API map on Windows (left) and on Linux (right)

As you can see, on Windows it maps the controllers correctly, but not on Linux. I’m showing the Swagger page to be more explicit, but if I access the routes manually, the behaviour is the same.

Does anyone know what could be and how to solve this problem? I have to make it work on Linux because my deployment target is a debian based server.

Below are some code that may be useful (Startup.cs and a Controller declaration)

Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {

        services.AddControllers();
        services.AddDbContext<Core.Contexts.ComiesContext>(o => {o.UseSqlServer("name=LocalComiesDBConn"); o.ConfigureWarnings(p => p. Ignore(30000));});
        services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo { Title = "comies_services", Version = "v1" }));
        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<Core.Contexts.ComiesContext>()
            .AddDefaultTokenProviders();

        var signingConfigurations = new Structures.ModelsConfigurations.SigningConfigurations(Configuration["TokenConfigurations:securityKey"]);
        services.AddSingleton(signingConfigurations);

        var tokenConfigurations = new AuthenticationConfiguration();
        new ConfigureFromConfigurationOptions<AuthenticationConfiguration>(Configuration.GetSection("TokenConfigurations")).Configure(tokenConfigurations);
        services.AddSingleton(tokenConfigurations);

        services.AddAuthentication(authOptions =>
        {
            authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;

        }).AddJwtBearer(jwtBearerOptions =>
        {
            var paramsValidation = jwtBearerOptions.TokenValidationParameters;

            paramsValidation.IssuerSigningKey = signingConfigurations.Key;
            paramsValidation.ValidAudience = tokenConfigurations.Audience;
            paramsValidation.ValidIssuer = tokenConfigurations.Issuer;

            paramsValidation.ValidateIssuerSigningKey = true;

            paramsValidation.ValidateLifetime = true;

            paramsValidation.ClockSkew = TimeSpan.Zero;
        });

        // Ativa o uso do token como forma de autorizar o acesso
        // a recursos deste projeto
        services.AddAuthorization(auth =>
        {
            
            auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
                .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                .RequireAuthenticatedUser().Build());
        });


        services.AddScoped<AuthenticatedOperator>();
        services.AddScoped<AuthenticationService>();
        services.AddTransient<UserManager<ApplicationUser>>();
        services.AddTransient<SignInManager<ApplicationUser>>();
    }

    // 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.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "comies_services v1"));
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }

AuthController.cs

[Route("api/v1/auth")]
[ApiController]
public class AuthenticationController : ControllerBase
{
    private readonly ComiesContext _context;

    private readonly AuthenticationService _authenticationService;

    public AuthenticationController(ComiesContext context, AuthenticationService authenticationService)
    {
        _context = context; _authenticationService = authenticationService;
    }


    // GET: api/<AuthenticationController>
    [HttpGet("register/template")]
    public async Task<ActionResult<Store>> Get()
    {
        ///hidden implementation, but trust me, this endpoint is working (when it's mapped)
    }

Source: Windows Questions

LEAVE A COMMENT