#411 Default webroot to wwwroot if the directory exists.

This commit is contained in:
Chris R 2015-10-22 09:27:53 -07:00
parent f2e7c49c36
commit 4702752384
1 changed files with 21 additions and 2 deletions

View File

@ -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);