C#C
C#3y ago
xdd

✅ Html/js Redirection also some Minimal api things

hi, don't found anything useful in web, so asking here. | i have this app -
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { WebRootPath = "StaticFiles" });

builder.Services.AddDbContext<PetProjContext>();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => options.LoginPath = "/login");
builder.Services.AddAuthorization();

var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/addproduct", [Authorize] () => "");
app.MapGet("/api/GetProducts", (PetProjContext db) => db.Products.ToList());
app.MapGet("product/{id}", (int id, PetProjContext db) => Console.WriteLine(id));
app.Run();

app.UseDefaultFiles();
app.UseStaticFiles();

cuz this these things and (screenshot 1), simple redirection in html like(<a href="/login"></a>) gets u to page and loads it correctly.

there is page itself (screenshot 2), and finally we get to problem. - how to make clicking product div redirect to /product/id ? i mean, am already doing it and getting (screenshot 3), is it somehow possible to on click to load index.html from staticfiles/product and after make another request to /product/id for get data to fill page?
image.png
image.png
Was this page helpful?