hapless.dev
hapless.dev
Explore posts from servers
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
have a great day mate!
23 replies
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
i really really appreciate it, thank you for your quick response, patience and guidance!
23 replies
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
not at all, from this point i can take a look by myself, thank you so much! i was scratching my head so much around this
23 replies
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
aha, i see
23 replies
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
i see, so and id have to map them to the specific routes on my controller i see right? like, for a more granular control over them?
23 replies
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
thank you so much!!! now it worked! however, i only added
builder.Services.AddRouting();
// ...
app.UseRouting();
app.MapControllers();
builder.Services.AddRouting();
// ...
app.UseRouting();
app.MapControllers();
when i tried to use app.UseEndpoints() the lsp would complain saying There is no argument given that corresponds to the required parameter 'configure' of 'EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder, Action<IEndpointRouteBuilder>) im using .net 8.0, i was curious on the message and when would i need to use it or any sort of example where id encounter that, what does that error mean and why did it work without it?
23 replies
CC#
Created by hapless.dev on 10/6/2023 in #help
✅ controller endpoint gets 404 when hit
you mean like initialized? sorry im new to .net and c# in general, i think builder.Services.AddControllers() should parse any controller that inherits from BaseController, or am i mistaken? this is how my program.cs looks like
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

using Services.AuthAPI.Data;
using Services.AuthAPI.Models;
using Services.AuthAPI.Service;
using Services.AuthAPI.Service.IService;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<AppDbContext>(option => {
option.UseSqlServer(builder.Configuration["User:DockerConnection"]);
});

// NOTE: This now makes dependency injection possible and passes the variables
// to initialize them with its environment variables
// TODO: Apply as secret
builder.Services.Configure<JwtOptions>(builder.Configuration.GetSection("ApiSettings:JwtOptions"));

// TODO: Investigate this line in depth
// IdentityRole can vary as far as I can see?
builder.Services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<AppDbContext>().AddDefaultTokenProviders();

builder.Services.AddScoped<IAuthService, AuthService>();

builder.Services.AddControllers();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();
// NOTE: Auth ALWAYS must be before authorization
app.UseAuthentication();
app.UseAuthorization();

ApplyMigration();
app.Run();

void ApplyMigration() {
using (var scope = app.Services.CreateScope()) {
var _db = scope.ServiceProvider.GetRequiredService<AppDbContext>();

if (_db.Database.GetPendingMigrations().Count() > 0) {
_db.Database.Migrate();
}
}
}
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

using Services.AuthAPI.Data;
using Services.AuthAPI.Models;
using Services.AuthAPI.Service;
using Services.AuthAPI.Service.IService;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<AppDbContext>(option => {
option.UseSqlServer(builder.Configuration["User:DockerConnection"]);
});

// NOTE: This now makes dependency injection possible and passes the variables
// to initialize them with its environment variables
// TODO: Apply as secret
builder.Services.Configure<JwtOptions>(builder.Configuration.GetSection("ApiSettings:JwtOptions"));

// TODO: Investigate this line in depth
// IdentityRole can vary as far as I can see?
builder.Services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<AppDbContext>().AddDefaultTokenProviders();

builder.Services.AddScoped<IAuthService, AuthService>();

builder.Services.AddControllers();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();
// NOTE: Auth ALWAYS must be before authorization
app.UseAuthentication();
app.UseAuthorization();

ApplyMigration();
app.Run();

void ApplyMigration() {
using (var scope = app.Services.CreateScope()) {
var _db = scope.ServiceProvider.GetRequiredService<AppDbContext>();

if (_db.Database.GetPendingMigrations().Count() > 0) {
_db.Database.Migrate();
}
}
}
23 replies