✅ Some web things
Soooo... i have this app
problem - On home page i have link which goes to /users, i wanted it to work like, first time when go to users, send users html page, and on this users html page wanted to make <ul> with event listener "onload" to request data. any advice?
using System;
using webtest;
class Prgram
{
static void Main(string[] args)
{
var dataSource = new List<Person>() {
new Person("David", 21),
new Person("Bob", 25),
new Person("Tom", 30),
new Person("Sam", 23),
};
var builder = WebApplication.CreateBuilder(
new WebApplicationOptions
{
WebRootPath = "StaticFiles"
}
);
var app = builder.Build();
app.MapGet("/users", async (context) =>
{
context.Response.ContentType = "text/html; charset=utf-8";
await context.Response.SendFileAsync("Html/users.html");
});
app.UseWhen(
context => context.Request.Path == "/users" && context.Request.Method == "GET",
appBuilder => appBuilder.Run(async context =>
{
await context.Response.WriteAsJsonAsync(dataSource);
})
);
app.MapGet("/", async (context) =>
{
context.Response.ContentType = "text/html; charset=utf-8";
await context.Response.SendFileAsync("Html/index.html");
});
app.Run();
}
}using System;
using webtest;
class Prgram
{
static void Main(string[] args)
{
var dataSource = new List<Person>() {
new Person("David", 21),
new Person("Bob", 25),
new Person("Tom", 30),
new Person("Sam", 23),
};
var builder = WebApplication.CreateBuilder(
new WebApplicationOptions
{
WebRootPath = "StaticFiles"
}
);
var app = builder.Build();
app.MapGet("/users", async (context) =>
{
context.Response.ContentType = "text/html; charset=utf-8";
await context.Response.SendFileAsync("Html/users.html");
});
app.UseWhen(
context => context.Request.Path == "/users" && context.Request.Method == "GET",
appBuilder => appBuilder.Run(async context =>
{
await context.Response.WriteAsJsonAsync(dataSource);
})
);
app.MapGet("/", async (context) =>
{
context.Response.ContentType = "text/html; charset=utf-8";
await context.Response.SendFileAsync("Html/index.html");
});
app.Run();
}
}problem - On home page i have link which goes to /users, i wanted it to work like, first time when go to users, send users html page, and on this users html page wanted to make <ul> with event listener "onload" to request data. any advice?