Skip to content

Commit 4702752

Browse files
committed
#411 Default webroot to wwwroot if the directory exists.
1 parent f2e7c49 commit 4702752

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Microsoft.AspNet.Hosting/HostingEnvironmentExtensions.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,27 @@ public static class HostingEnvironmentExtensions
1616

1717
public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, IConfiguration config)
1818
{
19-
var webRoot = config?[WebRootKey] ?? string.Empty;
20-
hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot);
19+
var webRoot = config?[WebRootKey];
20+
if (webRoot == null)
21+
{
22+
// Default to /wwwroot if it exists.
23+
var wwwroot = Path.Combine(applicationBasePath, "wwwroot");
24+
if (Directory.Exists(wwwroot))
25+
{
26+
hostingEnvironment.WebRootPath = wwwroot;
27+
}
28+
else
29+
{
30+
hostingEnvironment.WebRootPath = applicationBasePath;
31+
}
32+
}
33+
else
34+
{
35+
hostingEnvironment.WebRootPath = Path.Combine(applicationBasePath, webRoot);
36+
}
37+
38+
hostingEnvironment.WebRootPath = Path.GetFullPath(hostingEnvironment.WebRootPath);
39+
2140
if (!Directory.Exists(hostingEnvironment.WebRootPath))
2241
{
2342
Directory.CreateDirectory(hostingEnvironment.WebRootPath);

0 commit comments

Comments
 (0)