{"id":657,"date":"2019-09-26T13:37:56","date_gmt":"2019-09-26T04:37:56","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=657"},"modified":"2019-09-26T13:37:56","modified_gmt":"2019-09-26T04:37:56","slug":"rewrite","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=657","title":{"rendered":"rewrite"},"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.Extensions.DependencyInjection;\r\nusing Microsoft.Extensions.Logging;\r\nusing Microsoft.AspNetCore;\r\nusing Microsoft.AspNetCore.Routing;\r\nusing Microsoft.AspNetCore.Rewrite; \/\/UseRewriter\r\n\r\nnamespace WebApplication1\r\n{\r\n    public class Startup\r\n    {\r\n        public Startup(IHostingEnvironment env, ILoggerFactory logger)\r\n        {\r\n        }\r\n\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            \/\/This is the only service available at ConfigureServices\r\n            services.AddRouting();\r\n        }\r\n\r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)\r\n        {\r\n            var options = new RewriteOptions()\r\n               .AddRedirect(\"\/$\", \"\/\"); \/\/redirect when path ends with \/\r\n\r\n            app.UseRewriter(options);\r\n\r\n            var routes = new RouteBuilder(app);\r\n            routes.MapGet(\"\", (context) =&gt; {\r\n                context.Response.Headers.Add(\"content-type\", \"text\/html\");\r\n                return context.Response.WriteAsync($\"Always display this page when path ends with \/ e.g. &lt;a href=\\\"\/hello-world\/\\\"&gt;\/hello-world\/&lt;\/a&gt; or &lt;a href=\\\"\/welcome\/everybody\/inthis\/train\/\\\"&gt;\/welcome\/everybody\/inthis\/train\/&lt;\/a&gt;.\");\r\n            });\r\n\r\n            app.UseRouter(routes.Build());\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 : Always display this page when path ends with \/ e.g. \/hello-world\/ or \/welcome\/everybody\/inthis\/train\/.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using Microsoft.AspNetCore.Hosting; \/\/IWebHostBuilder using Microsoft.AspNetCore.Builder; \/\/IApplicationBuilder using Microsoft.AspNetCore.Http; \/\/WriteAsync using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Rewrite; \/\/UseRewriter namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger) { } public void ConfigureServices(IServiceCollection services) { \/\/This is the only service available at ConfigureServices services.AddRouting(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env,\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=657\">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-657","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\/657","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=657"}],"version-history":[{"count":1,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":658,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions\/658"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}