예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }


            app.UseMyCustomMiddleware();
            app.UseStaticFiles();
            app.UseSession();

            app.MapWhen(context =>
            {
                return(context.Request.Path.Value.Contains("one"));
            }, app1 =>
            {
                app1.Run(async context =>
                {
                    await context.Response.WriteAsync("<h1>one is in the path</h1>");
                });
            });

            app.Map("/session", sessionApp =>
            {
                sessionApp.Run(async context =>
                {
                    await SessionSample.SessionAsync(context);
                });
            });

            app.Map("/hello", app1 =>
            {
                app1.Run(async context =>
                {
                    var controller  = app1.ApplicationServices.GetService <MyController>();
                    string response = controller.Index("Katharina");
                    await context.Response.WriteAsync($"<div>{response}</div>");
                });
            });

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("<h1>Hello World!</h1>");
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();        // add middleware for static files
            app.UseSession();

            app.Map("/mycontroller", app1 =>
            {
                app1.Run(async context =>
                {
                    string name    = context.Request.Query["name"];
                    var controller = app1.ApplicationServices.GetService <HelloController>();
                    string result  = controller.Index(name);
                    await context.Response.WriteAsync(result);  // TODO: encoding!!
                });
            });

            app.Map("/session", sessionApp =>
            {
                sessionApp.Run(async context =>
                {
                    await SessionSample.SessionAsync(context);
                });
            });

            app.Map("/requestsample", app1 =>
            {
                app1.Run(async(context) =>
                {
                    string result = string.Empty;
                    switch (context.Request.Path.Value.ToLower())
                    {
                    case "/header":
                        result = RequestAndResponseSample.GetHeaderInformation(context.Request);
                        break;

                    case "/add":
                        result = RequestAndResponseSample.QueryString(context.Request);
                        break;

                    case "/content":
                        result = RequestAndResponseSample.Content(context.Request);
                        break;

                    case "/encoded":
                        result = RequestAndResponseSample.ContentEncoded(context.Request);
                        break;

                    case "/form":
                        result = RequestAndResponseSample.GetForm(context.Request);
                        break;

                    case "/writecookie":
                        result = RequestAndResponseSample.WriteCookie(context.Response);
                        break;

                    case "/readcookie":
                        result = RequestAndResponseSample.ReadCookie(context.Request);
                        break;

                    case "/json":
                        result = RequestAndResponseSample.GetJson(context.Response);
                        break;

                    default:
                        result = RequestAndResponseSample.GetRequestInformation(context.Request);
                        break;
                    }
                    await context.Response.WriteAsync(result);
                });
            });

            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }