{"id":570,"date":"2019-09-24T14:08:54","date_gmt":"2019-09-24T05:08:54","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=570"},"modified":"2019-09-24T14:08:54","modified_gmt":"2019-09-24T05:08:54","slug":"hello-world-with-ihostingenvironment","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=570","title":{"rendered":"hello-world-with-IHostingEnvironment"},"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 Microsoft.Extensions.Logging; \/\/ILoggerFactory\r\nusing Microsoft.Extensions.DependencyInjection;\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            \/\/These are two services available at constructor\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        }\r\n\r\n        \/\/StartUP  \r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env,  ILoggerFactory logger)\r\n        {\r\n            var applicationName = $\"&lt;tr&gt;&lt;td&gt;ApplicationName&lt;\/td&gt;&lt;td&gt;{env.ApplicationName}&lt;\/td&gt;&lt;\/tr&gt;\";\r\n            var contentRootPath = $\"&lt;tr&gt;&lt;td&gt;ContentRootPath&lt;\/td&gt;&lt;td&gt;{env.ContentRootPath}&lt;\/td&gt;&lt;\/tr&gt;\";\r\n            var contentRootFileProvider = $\"&lt;tr&gt;&lt;td&gt;ContentRootFileProvider&lt;\/td&gt;&lt;td&gt;{env.ContentRootFileProvider}&lt;\/td&gt;&lt;\/tr&gt;\";\r\n            var environmentName = $\"&lt;tr&gt;&lt;td&gt;EnvironmentName&lt;\/td&gt;&lt;td&gt;{env.EnvironmentName}&lt;\/td&gt;&lt;\/tr&gt;\";\r\n            var webRootPath = $\"&lt;tr&gt;&lt;td&gt;WebRootPath&lt;\/td&gt;&lt;td&gt;{env.WebRootPath}&lt;\/td&gt;&lt;\/tr&gt;\";\r\n            var webRootFileProvider = $\"&lt;tr&gt;&lt;td&gt;WebRootFileProvider&lt;\/td&gt;&lt;td&gt;{env.WebRootFileProvider}&lt;\/td&gt;&lt;\/tr&gt;\";\r\n\r\n            var content = $\"&lt;html&gt;&lt;body&gt;&lt;table&gt;&lt;tbody&gt;&lt;h1&gt;Complete list of IHostingEnvironment properties&lt;\/h1&gt;{applicationName}{contentRootPath}{contentRootFileProvider}{environmentName}{webRootPath}{webRootFileProvider}&lt;\/tbody&gt;&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;\";\r\n\r\n\r\n            app.Run(context =&gt;\r\n            {\r\n                context.Response.ContentType = \"text\/html\";\r\n                return context.Response.WriteAsync(content);\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}\r\n<\/pre>\n<p>\uacb0\uacfc :<br \/>\nComplete list of IHostingEnvironment properties<\/p>\n<p>ApplicationName WebApplication1<br \/>\nContentRootPath D:\\Sample\\MVC\\WebApplication2\\WebApplication1<br \/>\nContentRootFileProvider Microsoft.Extensions.FileProviders.PhysicalFileProvider<br \/>\nEnvironmentName Development<br \/>\nWebRootPath<br \/>\nWebRootFileProvider Microsoft.Extensions.FileProviders.NullFileProvider <\/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 Microsoft.Extensions.Logging; \/\/ILoggerFactory using Microsoft.Extensions.DependencyInjection; namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger) { \/\/These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { \/\/This is the only service available at ConfigureServices } \/\/StartUP public void\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=570\">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-570","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\/570","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=570"}],"version-history":[{"count":1,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}