{"id":705,"date":"2019-10-07T14:32:26","date_gmt":"2019-10-07T05:32:26","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=705"},"modified":"2019-10-07T14:37:05","modified_gmt":"2019-10-07T05:37:05","slug":"mvc-routing-1","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=705","title":{"rendered":"MVC routing-1"},"content":{"rendered":"\n<pre class=\"lang:c# decode:true \" >using Microsoft.AspNetCore.Hosting;\r\nusing Microsoft.AspNetCore.Builder;\r\nusing Microsoft.AspNetCore.Http;\r\nusing Microsoft.Extensions.Logging;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusing Microsoft.AspNetCore;\r\nusing Microsoft.Extensions.Configuration;\r\nusing Microsoft.AspNetCore.Mvc;\r\n\r\nnamespace MvcRouting\r\n{\r\n    public class Startup\r\n    {\r\n        public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration)\r\n        {\r\n            \/\/These are three services available at constructor\r\n        }\r\n\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddMvcCore().\r\n                SetCompatibilityVersion(CompatibilityVersion.Version_2_1);\r\n        }\r\n\r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration)\r\n        {\r\n            app.UseMvc(routes =&gt; {\r\n                routes.MapRoute(\r\n                    name: \"home\",\r\n                    template: \"\/\",\r\n                    defaults: new { controller = \"Home\", action = \"Index\" });\r\n\r\n                routes.MapRoute(\r\n                    name: \"default\",\r\n                    template: \"{controller}\/{action}\",\r\n                    defaults: new { controller = \"Home\", action = \"Index\" });\r\n\r\n            });\r\n        }\r\n    }\r\n\r\n    public class HomeController : Controller\r\n    {\r\n        public ActionResult Index()\r\n        {\r\n            return new ContentResult\r\n            {\r\n                Content = @\"\r\n                &lt;html&gt;&lt;body&gt;\r\n                &lt;b&gt;Hello World&lt;\/b&gt;\r\n                &lt;br\/&gt;&lt;br\/&gt;\r\n                The following links call the same controller and action.\r\n                &lt;ul&gt;\r\n                    &lt;li&gt;&lt;a href=\"\"\/\"\"&gt;\/&lt;\/a&gt;&lt;\/li&gt;\r\n                    &lt;li&gt;&lt;a href=\"\"\/Home\"\"&gt;\/Home&lt;\/a&gt;&lt;\/li&gt;\r\n                    &lt;li&gt;&lt;a href=\"\"\/Home\/index\"\"&gt;\/Home\/index&lt;\/a&gt;&lt;\/li&gt;\r\n                &lt;\/ul&gt;\r\n                &lt;\/body&gt;&lt;\/html&gt;\",\r\n                ContentType = \"text\/html\"\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 : Hello World <\/p>\n<p>The following links call the same controller and action. \u2022\/<br \/>\n\u2022\/home<br \/>\n\u2022\/home\/index<\/p>\n<p>\ub3d9\uc77c :<\/p>\n<pre class=\"lang:c# decode:true \" >namespace MvcRouting\r\n{\r\n    public class Startup\r\n    {\r\n        public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration)\r\n        {\r\n            \/\/These are three services available at constructor\r\n        }\r\n\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddMvcCore().\r\n                SetCompatibilityVersion(CompatibilityVersion.Version_2_1);\r\n        }\r\n\r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration)\r\n        {\r\n            app.UseMvc();\r\n        }\r\n    }\r\n\r\n    [Route(\"\")]\r\n    [Route(\"Home\")]\r\n    [Route(\"Home\/Index\")]\r\n    public class HomeController : Controller\r\n    {\r\n        public ActionResult Index()\r\n        {\r\n            return new ContentResult\r\n            {\r\n                Content = @\"\r\n                &lt;html&gt;&lt;body&gt;\r\n                &lt;b&gt;Hello World&lt;\/b&gt;\r\n                &lt;br\/&gt;&lt;br\/&gt;\r\n                The following links call the same controller and action.\r\n                &lt;ul&gt;\r\n                    &lt;li&gt;&lt;a href=\"\"\/\"\"&gt;\/&lt;\/a&gt;&lt;\/li&gt;\r\n                    &lt;li&gt;&lt;a href=\"\"\/home\"\"&gt;\/home&lt;\/a&gt;&lt;\/li&gt;\r\n                    &lt;li&gt;&lt;a href=\"\"\/home\/index\"\"&gt;\/home\/index&lt;\/a&gt;&lt;\/li&gt;\r\n                &lt;\/ul&gt;\r\n                &lt;\/body&gt;&lt;\/html&gt;\",\r\n                ContentType = \"text\/html\"\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","protected":false},"excerpt":{"rendered":"<p>using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Mvc; namespace MvcRouting { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { \/\/These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger,\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=705\">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-705","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\/705","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=705"}],"version-history":[{"count":2,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/705\/revisions"}],"predecessor-version":[{"id":707,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/705\/revisions\/707"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}