Ejemplo n.º 1
0
        // 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.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    string menu    = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string content = HtmlHelper.HtmlTrangchu();
                    string html    = HtmlHelper.HtmlDocument("Trang chủ", menu + content);
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/RequestInfo", async(context) => {
                    string menu        = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string requestinfo = RequestProcess.RequestInfo(context.Request).HtmlTag("div", "container");
                    string html        = HtmlHelper.HtmlDocument("Thông tin Request", (menu + requestinfo));
                    await context.Response.WriteAsync(html);
                });


                endpoints.Map("/Form", async(context) => {
                    string menu     = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string formhtml = await RequestProcess.FormProcess(context.Request);
                    formhtml        = formhtml.HtmlTag("div", "container");
                    string html     = HtmlHelper.HtmlDocument("Form Post", (menu + formhtml));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Encoding", async(context) => {
                    string menu   = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string htmlec = RequestProcess.Encoding(context.Request).HtmlTag("div", "container");
                    string html   = HtmlHelper.HtmlDocument("Encoding", (menu + htmlec));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Cookies/{*action}", async(context) => {
                    string menu    = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string cookies = RequestProcess.Cookies(context.Request, context.Response).HtmlTag("div", "container");
                    string html    = HtmlHelper.HtmlDocument("Đọc / Ghi Cookies", (menu + cookies));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Json", async(context) => {
                    string Json = RequestProcess.GetJson();
                    context.Response.ContentType = "application/json";
                    await context.Response.WriteAsync(Json);
                });
            });
        }
Ejemplo n.º 2
0
        // 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();                               // Đăng ký Middleware Session vào Pipeline

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    string menu    = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string content = HtmlHelper.HtmlTrangchu();
                    string html    = HtmlHelper.HtmlDocument("Trang chủ", menu + content);
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/RequestInfo", 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);
                });


                endpoints.Map("/Form", async(context) => {
                    string menu     = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string formhtml = await RequestProcess.FormProcess(context.Request);
                    formhtml        = formhtml.HtmlTag("div", "container");
                    string html     = HtmlHelper.HtmlDocument("Form Post", (menu + formhtml));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Encoding", async(context) => {
                    string menu   = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string htmlec = RequestProcess.Encoding(context.Request).HtmlTag("div", "container");
                    string html   = HtmlHelper.HtmlDocument("Encoding", (menu + htmlec));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Cookies/{*action}", async(context) => {
                    string menu    = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string cookies = RequestProcess.Cookies(context.Request, context.Response).HtmlTag("div", "container");
                    string html    = HtmlHelper.HtmlDocument("Đọc / Ghi Cookies", (menu + cookies));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Json", async(context) => {
                    string Json = RequestProcess.GetJson();
                    context.Response.ContentType = "application/json";
                    await context.Response.WriteAsync(Json);
                });

                endpoints.MapGet("/Product", async(context) => {
                    await context.RequestServices.GetService <ProductController>().List(context);
                });

                endpoints.MapGet("/allservice", 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);
                });


                endpoints.MapGet("/ShowOptions", async context => {
                    StringBuilder stb            = new StringBuilder();
                    IConfiguration configuration = context.RequestServices.GetService <IConfiguration>();

                    var testoptions = configuration.GetSection("TestOptions");      // Đọc một Section
                    var opt_key1    = testoptions["opt_key1"];                      // Đọc giá trị trong Section
                    var k1          = testoptions.GetSection("opt_key2")["k1"];     // Đọc giá trị trong Section con
                    var k2          = configuration["TestOptions:opt_key2:k2"];     // Đọc giá trị trong Section

                    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"));
                });
            });
        }
Ejemplo n.º 3
0
        // 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.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    string menu    = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string content = HtmlHelper.HtmlTrangchu();
                    string html    = HtmlHelper.HtmlDocument("Trang chủ", menu + content);
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/RequestInfo", async(context) => {
                    string menu        = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string requestinfo = RequestProcess.RequestInfo(context.Request).HtmlTag("div", "container");
                    string html        = HtmlHelper.HtmlDocument("Thông tin Request", (menu + requestinfo));
                    await context.Response.WriteAsync(html);
                });


                endpoints.Map("/Form", async(context) => {
                    string menu     = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string formhtml = await RequestProcess.FormProcess(context.Request);
                    formhtml        = formhtml.HtmlTag("div", "container");
                    string html     = HtmlHelper.HtmlDocument("Form Post", (menu + formhtml));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Encoding", async(context) => {
                    string menu   = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string htmlec = RequestProcess.Encoding(context.Request).HtmlTag("div", "container");
                    string html   = HtmlHelper.HtmlDocument("Encoding", (menu + htmlec));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Cookies/{*action}", async(context) => {
                    string menu    = HtmlHelper.MenuTop(HtmlHelper.DefaultMenuTopItems(), context.Request);
                    string cookies = RequestProcess.Cookies(context.Request, context.Response).HtmlTag("div", "container");
                    string html    = HtmlHelper.HtmlDocument("Đọc / Ghi Cookies", (menu + cookies));
                    await context.Response.WriteAsync(html);
                });

                endpoints.MapGet("/Json", async(context) => {
                    string Json = RequestProcess.GetJson();
                    context.Response.ContentType = "application/json";
                    await context.Response.WriteAsync(Json);
                });

                endpoints.MapGet("/Product", async(context) => {
                    await context.RequestServices.GetService <ProductController>().List(context);
                });

                endpoints.MapGet("/allservice", 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);
                });
            });
        }