I have a large number of .cshtml files with no code-behind that I want to serve from an Azure file share as part of a website that also has other, more typical, content. Note that I am using AddRazorRuntimeCompilation and providing a file provider to the Razor engine, not the static file handler, as I do need these files rendered and not just returned as text
builder.Services.AddRazorPages().AddRazorRuntimeCompilation(opts =>
{
// replace the default provider with one that handles a custom path and uses the default for the rest
opts.FileProviders.Add(new ExternalFileProvider("/Pages/path/toVirtualize/", hiePath, opts.FileProviders[0]));
opts.FileProviders.RemoveAt(0);
}
);
The toVirtualize folder exists down both the regular (under Pages/ in the web folder) and virtualized path, "hiePath" being the location I want to serve files from. The hiePath folder has many files. The same folder under /Pages has only three and importantly one, /Pages/path/toVirtualize/1/000001.cshtml, is labelled "unmapped".
The handler uses its logic if the requested path is or is under /Pages/path/toVirtualize and otherwise invokes the call on the original provider.
Everything works from my desktop with the virtual tree in a folder outside the website, with all the Razor pages rendered. When I publish to Azure, only the files that exist in the version of the folder under Pages/ are rendered... but the version of the file is from my handler, without the label. (When I first configured Azure I had a typo in the file share path and then I saw the "unmapped" label.)
I added code to IFileProvider.GetDirectoryContents to list all directories it was invoked with. I added code to IFileProvider.GetFileInfo to throw an exception and include that list in the message when called for a file in the virtualized path.
After that, the initial page loads in both Dev and Azure. If I try to go to the /Pages/path/toVirtualize/000001 page I get different exception messages.
Desktop: File '/Pages/path/toVirtualize/1/000001.cshtml' was requested. Previously folders /Areas, /Pages, ...(and 25 subfolders directly or indirectly under Pages, including folders that only exist in the virtual tree) were viewed.
Azure: File '/Pages/path/toVirtualize/1/000001.cshtml' was requested. Previously folders /Areas, /Pages were viewed.
I expected the same behavior in both contexts. Why are the subdirectories not iterated when running in Azure?