Bug found in CMS 12 - Mapping CMS content in router breaks StaticFileMiddleware's ability to provide embedded files.

Vote:
 

I found this issue while playing around with using Blazor as a renderer for CMS content. Serverside-blazor has a dependency of a .js-file located as an embedded resource within AspNetCore. Normally, when requesting the url "/_framework/blazor.server.js", the Static file middleware usually mange to provide this file. However, when trying to access this file with CMS set up, the file was no longer to be found.

I managed to narrow down the issue to this.

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapContent(); //This is the culprit!
            });

So the issue is that when Optimizely registers the routing for content, it overwrites the file providers within the StaticFileOptions instance, without regarding that the change affects the StaticFileMiddleware.

The workaround is simply to override Optimizelys override...

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();

                var opt = endpoints.ServiceProvider.GetRequiredService<IOptions<StaticFileOptions>>().Value;
                var realprovider = opt.FileProvider;

                endpoints.MapContent(); //Will destroy the correct fileprovider!

                opt.FileProvider = new CompositeFileProvider(realprovider, opt.FileProvider); //Ensure all providers, both original and Episerver ones, are included

            });

This is very ugly and i believe that the PhysicalFileProvider is now mentioned multiple times in the composite tree. It shouldn't affect functionality and as long as there is no collision between Optimizely static files and project-specific static files the fix should do it. However, i think Optimizely needs to get this straighted out. You should not tamper with internal Asp.Net components.

#265389
Oct 21, 2021 9:21
Vote:
 

If it's a bug I'd log it with Optimizely Support and pop it here https://world.optimizely.com/forum/developer-forum/Problems-and-bugs/ 

#265392
Oct 21, 2021 10:26
Vote:
 

Hi Scott, thank you for your reply. I've submited a ticket on Optimizely support on the topic, but you are correct i placed this topic in the wrong forum. Is there any way to relocate a topic to another forum?

#266280
Nov 05, 2021 12:04
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.