diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorProjectFileSystem.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorProjectFileSystem.cs index 8fdefe7d1c..26b03a14ef 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorProjectFileSystem.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorProjectFileSystem.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language var file = new FileInfo(absolutePath); if (!absolutePath.StartsWith(absoluteBasePath)) { - throw new InvalidOperationException($"The file '{file.FullName}' is not a descendent of the base path '{absoluteBasePath}'."); + throw new InvalidOperationException($"The file '{absolutePath}' is not a descendent of the base path '{absoluteBasePath}'."); } var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator @@ -68,9 +68,15 @@ namespace Microsoft.AspNetCore.Razor.Language throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path)); } - var absolutePath = path; - if (!absolutePath.StartsWith(Root, StringComparison.OrdinalIgnoreCase)) + var absolutePath = path.Replace('\\', '/'); + + // Check if the given path is an absolute path. It is absolute if, + // 1. It starts with Root or + // 2. It is a network share path and starts with a '//'. Eg. //servername/some/network/folder + if (!absolutePath.StartsWith(Root, StringComparison.OrdinalIgnoreCase) && + !absolutePath.StartsWith("//", StringComparison.OrdinalIgnoreCase)) { + // This is not an absolute path. Strip the leading slash if any and combine it with Root. if (path[0] == '/' || path[0] == '\\') { path = path.Substring(1);