1

I'm running Tridion 9.6, DXA 2.2.9 .net and the GraphQL providers to CD Services. Topology Manager is installed and configured for both hostnames and contexts.

I have a Publication identified by hostname and context (/en). I do not have a Publication mapped to the root context (/).

DXA works fine for requests to the hostname/en URLs. However, I can't seem to serve any static files that are in the root of the website (e.g. /js/main.js). These are all static files on the filesystem. Instead, I get error Sdl.Web.Common.DxaUnknownLocalizationException: No matching Localization found for URL coming from the StaticContentModule:

   Sdl.Web.Mvc.Configuration.WebRequestContext.get_Localization() in C:\DXAGitHub\dxa-suite\repositories\dxa-web-application-dotnet\Sdl.Web.Mvc\Configuration\WebRequestContext.cs:28
   Sdl.Web.Mvc.Statics.StaticContentModule.OnPreRequestHandlerExecute(Object sender, EventArgs eventArgs) in C:\DXAGitHub\dxa-suite\repositories\dxa-web-application-dotnet\Sdl.Web.Mvc\Statics\StaticContentModule.cs:121
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +223
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +220
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +94

Looking at the source code (https://github.com/RWS/dxa-web-application-dotnet/blob/5c24bcc990f53a7357362b94e2526fd05a3f710b/Sdl.Web.Mvc/Statics/StaticContentModule.cs#L123), I see it needs a Localization object.

There is no Publication that maps to the root of the website, therefore there is no Localization available.

How can one server static content in this case?

Notes:

How can I prevent some URL patterns be handled by the StaticContentModule?

So far, all I can see is modify the open source StaticContentModule to allow it requests when there is no Localization object.

Looking forward to your thoughts and thanks in advance!

1 Answer 1

3

Interesting! Indeed, in general, DXA assumes that all HTTP requests can be mapped to a Localization/Publication.

However, there is indeed the IUnknownLocalizationHandler extension point to be able to determine what should happen if a Localization cannot be resolved in the regular way. This was introduced for a specific use case (Just-In-Time provisioning) and apparently it can't cover your scenario.

Alternatively, you could look into creating your own ILocalizationResolver implementation (based on the default one).

Or you could create your own HttpModule (which runs before the StaticContentModule) which sets a dummy WebRequestContext.Localization for these "localizationless" URLs)

1
  • Thanks Rick, -- I accept this as answer. I ended up using my own IUnknownLocalizationHandler implementation to create a dummy Localization and then extend (lobotomize) the StaticContentModule to use use the dummy Localization in case of a Location-less request. I use this together with some Regular Expression patterns defined in AppConfig to only serve the content if the URL matches the regex. Nov 23, 2022 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.