// 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.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.Map("/Product", app => { app.Run(async(context) => { // Gọi đến dịch vụ ProductController var productcontroller = app.ApplicationServices.GetService <ProductController> (); await productcontroller.List(context); }); }); app.Map("/ShowOptions", appOptions => { appOptions.Run(async(context) => { StringBuilder stb = new StringBuilder(); IConfiguration configuration = appOptions.ApplicationServices.GetService <IConfiguration> (); TestOptions testoptions = configuration.GetSection("TestOptions").Get <TestOptions> (); var opt_key1 = testoptions.opt_key1; var k1 = testoptions.opt_key2.k1; var k2 = testoptions.opt_key2.k2; stb.Append($"TestOptions.opt_key1: {opt_key1}\n"); stb.Append($"TestOptions.opt_key2.k1: {k1}\n"); stb.Append($"TestOptions.opt_key2.k2: {k2}\n"); await context.Response.WriteAsync(stb.ToString().HtmlTag("pre")); }); }); app.Map("/allservice", app01 => { app01.Run(async(context) => { var stringBuilder = new StringBuilder(); stringBuilder.Append("<tr><th>Tên</th><th>Lifetime</th><th>Tên đầy đủ</th></tr>"); foreach (var service in _services) { string tr = service.ServiceType.Name.ToString().HtmlTag("td") + service.Lifetime.ToString().HtmlTag("td") + service.ServiceType.FullName.HtmlTag("td"); stringBuilder.Append(tr.HtmlTag("tr")); } string htmlallservice = stringBuilder.ToString().HtmlTag("table", "table table-bordered table-sm"); string html = HtmlHelper.HtmlDocument("Các dịch vụ", (htmlallservice)); await context.Response.WriteAsync(html); }); }); app.Map("/RequestInfo", app01 => { app01.Run(async(context) => { string menu = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request); string requestinfo = RequestProcess.RequestInfo(context.Request).HtmlTag("div", "container"); string accessinfo = ProductController.CountAccessInfo(context).HtmlTag("div", "container"); string html = HtmlHelper.HtmlDocument("Thông tin Request", (menu + accessinfo + requestinfo)); await context.Response.WriteAsync(html); }); }); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); }); }
// 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.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.Map("/Product", app => { app.Run(async(context) => { // Gọi đến dịch vụ ProductController var productcontroller = app.ApplicationServices.GetService <ProductController> (); await productcontroller.List(context); }); }); app.MapWhen( (context) => { return(context.Request.Path.Value.StartsWith("/Abcxyz")); }, appProduct => { appProduct.Run(async(context) => { await appProduct.ApplicationServices.GetService <ProductController> ().List(context); }); }); app.Map("/allservice", app01 => { app01.Run(async(context) => { var stringBuilder = new StringBuilder(); stringBuilder.Append("<tr><th>Tên</th><th>Lifetime</th><th>Tên đầy đủ</th></tr>"); foreach (var service in _services) { string tr = service.ServiceType.Name.ToString().HtmlTag("td") + service.Lifetime.ToString().HtmlTag("td") + service.ServiceType.FullName.HtmlTag("td"); stringBuilder.Append(tr.HtmlTag("tr")); } string htmlallservice = stringBuilder.ToString().HtmlTag("table", "table table-bordered table-sm"); string html = HtmlHelper.HtmlDocument("Các dịch vụ", (htmlallservice)); await context.Response.WriteAsync(html); }); }); app.Map("/RequestInfo", app01 => { app01.Run(async(context) => { string menu = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request); string requestinfo = RequestProcess.RequestInfo(context.Request).HtmlTag("div", "container"); string accessinfo = ProductController.CountAccessInfo(context).HtmlTag("div", "container"); string html = HtmlHelper.HtmlDocument("Thông tin Request", (menu + accessinfo + requestinfo)); await context.Response.WriteAsync(html); }); }); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); }); }