{"id":648,"date":"2019-09-25T17:01:08","date_gmt":"2019-09-25T08:01:08","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=648"},"modified":"2019-09-25T17:01:08","modified_gmt":"2019-09-25T08:01:08","slug":"middleware-7","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=648","title":{"rendered":"middleware-7"},"content":{"rendered":"\n<pre class=\"lang:default decode:true \" >using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder\r\nusing Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder\r\nusing Microsoft.AspNetCore.Http; \/\/WriteAsync\r\nusing System.Threading.Tasks;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.AspNetCore.Builder.Extensions;\r\nusing Microsoft.AspNetCore;\r\n\r\nnamespace WebApplication1\r\n{\r\n        public class Startup\r\n        {\r\n            public void Configure(IApplicationBuilder app)\r\n            {\r\n                \/\/Use MapMiddleWare and MapWhenMiddlware directly\r\n                var whenOption = new MapWhenOptions\r\n                {\r\n                    Branch =\r\n                        context =&gt;\r\n                            context.Response.WriteAsync($\"MapWhenMiddleware| Path: {context.Request.Path} - Path Base: {context.Request.PathBase}\"),\r\n                    Predicate = context =&gt; context.Request.Path.Value.Contains(\"hello\")\r\n                };\r\n\r\n                app.UseMiddleware&lt;MapWhenMiddleware&gt;(whenOption);\r\n\r\n                var mapOption = new MapOptions\r\n                {\r\n                    Branch =\r\n                        context =&gt;\r\n                            context.Response.WriteAsync($\"MapMiddleware| Path: {context.Request.Path} - Path Base: {context.Request.PathBase}\"),\r\n                    PathMatch = \"\/greetings\"\r\n                };\r\n\r\n                app.UseMiddleware&lt;MapMiddleware&gt;(mapOption);\r\n\r\n                app.Run(context =&gt;\r\n                {\r\n                    context.Response.Headers.Add(\"content-type\", \"text\/html\");\r\n                    return context.Response.WriteAsync(@\"\r\n                       &lt;a href=\"\"\/hello\"\"&gt;\/hello&lt;\/a&gt; &lt;a href=\"\"\/greetings\"\"&gt;\/greetings&lt;\/a&gt;\r\n                    \");\r\n                });\r\n            }\r\n    }\r\n\r\n        public class Program\r\n        {\r\n            public static void Main(string[] args)\r\n            {\r\n                CreateWebHostBuilder(args).Build().Run();\r\n            }\r\n\r\n            public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;\r\n                WebHost.CreateDefaultBuilder(args)\r\n                    .UseStartup&lt;Startup&gt;()\r\n                    .UseEnvironment(\"Development\");\r\n        }\r\n}<\/pre>\n<p>\uacb0\uacfc: MapWhenMiddleware| Path: \/hello &#8211; Path Base:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder using Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder using Microsoft.AspNetCore.Http; \/\/WriteAsync using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Builder.Extensions; using Microsoft.AspNetCore; namespace WebApplication1 { public class Startup { public void Configure(IApplicationBuilder app) { \/\/Use MapMiddleWare and MapWhenMiddlware directly var whenOption = new MapWhenOptions { Branch = context =&gt; context.Response.WriteAsync($&#8221;MapWhenMiddleware| Path: {context.Request.Path} &#8211; Path Base: {context.Request.PathBase}&#8221;), Predicate = context =&gt;\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=648\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[108],"tags":[],"class_list":["post-648","post","type-post","status-publish","format-standard","hentry","category-net-core"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=648"}],"version-history":[{"count":1,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":649,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions\/649"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}