From 4702752384ca4fbd447f34fcdb4385a8b1947ff4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 22 Oct 2015 09:27:53 -0700 Subject: [PATCH] #411 Default webroot to wwwroot if the directory exists. --- .../HostingEnvironmentExtensions.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs index 59aae860dc..4ff521aefb 100644 --- a/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs @@ -16,8 +16,27 @@ namespace Microsoft.AspNet.Hosting public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, IConfiguration config) { - var webRoot = config?[WebRootKey] ?? string.Empty; - hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot); + var webRoot = config?[WebRootKey]; + if (webRoot == null) + { + // Default to /wwwroot if it exists. + var wwwroot = Path.Combine(applicationBasePath, "wwwroot"); + if (Directory.Exists(wwwroot)) + { + hostingEnvironment.WebRootPath = wwwroot; + } + else + { + hostingEnvironment.WebRootPath = applicationBasePath; + } + } + else + { + hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot); + } + + hostingEnvironment.WebRootPath = Path.GetFullPath(hostingEnvironment.WebRootPath); + if (!Directory.Exists(hostingEnvironment.WebRootPath)) { Directory.CreateDirectory(hostingEnvironment.WebRootPath);