C
C#15mo ago
wwww

✅ 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();
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();
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?
2 Replies
Pobiega
Pobiega15mo ago
you won't be able to do product/5 etc with static files, as it needs client side routing or server side handling of the route. What you can do is /product/?id=5 and then use javascript to read the querystring
wwww
wwwwOP15mo ago
badhun1UA
Want results from more Discord servers?
Add your server