{"id":640,"date":"2019-09-25T16:38:55","date_gmt":"2019-09-25T07:38:55","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=640"},"modified":"2019-09-25T16:38:55","modified_gmt":"2019-09-25T07:38:55","slug":"middleware-3","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=640","title":{"rendered":"middleware-3"},"content":{"rendered":"\n<pre class=\"lang:c# decode:true \" >using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder\r\nusing Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder\r\nusing Microsoft.AspNetCore.Http; \/\/WriteAsync\r\nusing Microsoft.AspNetCore; \/\/webHost\r\nusing System.IO;\r\nusing System.Threading.Tasks;\r\n\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                app.UseMiddleware&lt;TerminalMiddleware&gt;();\r\n            }\r\n        }\r\n\r\n        \/\/A middleware class in ASP.NET Core is simply a class that \r\n        \/\/ - Take a constructor with RequestDelegate\r\n        \/\/ - implements Invoke method taking HttpContext and returning Task\r\n        \/\/If you take a look at this code, it cannot be any simpler.\r\n        \/\/This is a terminal middleware. It does not invoke the subsequent middleware. It just returns its own response and that's it.\r\n\r\n        public class TerminalMiddleware\r\n        {\r\n            public TerminalMiddleware(RequestDelegate next)\r\n            {\r\n                \/\/We are not using the parameter next in this middleware since this middleware is terminal\r\n            }\r\n\r\n            public async Task Invoke(HttpContext context)\r\n            {\r\n                await context.Response.WriteAsync(\"Hello world\");\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 : Hello world<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder using Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder using Microsoft.AspNetCore.Http; \/\/WriteAsync using Microsoft.AspNetCore; \/\/webHost using System.IO; using System.Threading.Tasks; namespace WebApplication1 { public class Startup { public void Configure(IApplicationBuilder app) { app.UseMiddleware&lt;TerminalMiddleware&gt;(); } } \/\/A middleware class in ASP.NET Core is simply a class that \/\/ &#8211; Take a constructor with RequestDelegate \/\/ &#8211; implements Invoke method taking\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=640\">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-640","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\/640","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=640"}],"version-history":[{"count":1,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/640\/revisions"}],"predecessor-version":[{"id":641,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/640\/revisions\/641"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}