Skip to content

Commit

Permalink
Changed AspNetAppBasePathLayoutRenderer to prioritize current directo…
Browse files Browse the repository at this point in the history
…ry (code layout) (#888)
  • Loading branch information
snakefoot authored Nov 19, 2022
1 parent ffc99bb commit 0176c44
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Shared/LayoutRenderers/AspNetAppBasePathLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal IHostEnvironment HostEnvironment
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
var contentRootPath = _contentRootPath ?? (_contentRootPath = ResolveContentRootPath());
builder.Append(contentRootPath ?? _currentAppPath);
builder.Append(contentRootPath ?? ResolveCurrentAppDirectory());
}

private IHostEnvironment ResolveHostEnvironment()
Expand Down Expand Up @@ -81,6 +81,9 @@ private static string TrimEndDirectorySeparator(string directoryPath)

private static string ResolveCurrentAppDirectory()
{
if (!string.IsNullOrEmpty(_currentAppPath))
return _currentAppPath;

#if ASP_NET_CORE
var currentAppPath = AppContext.BaseDirectory;
#else
Expand All @@ -96,23 +99,20 @@ private static string ResolveCurrentAppDirectory()
{
currentBasePath = currentAppPath; // Avoid using Windows-System32 as current directory
}
return currentBasePath;
return _currentAppPath = TrimEndDirectorySeparator(currentBasePath);
}
catch
{
// Not supported or access denied
return currentAppPath;
return _currentAppPath = TrimEndDirectorySeparator(currentAppPath);
}
}

/// <inheritdoc/>
protected override void InitializeLayoutRenderer()
{
if (string.IsNullOrEmpty(_currentAppPath))
{
// Capture current directory at startup, before it changes
_currentAppPath = TrimEndDirectorySeparator(ResolveCurrentAppDirectory());
}
ResolveCurrentAppDirectory(); // Capture current directory at startup, before it changes
base.InitializeLayoutRenderer();
}

/// <inheritdoc/>
Expand Down

0 comments on commit 0176c44

Please sign in to comment.