Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support URLs which don't map to a Publication in CM #43

Open
jhorsman opened this issue Feb 16, 2017 · 3 comments
Open

Support URLs which don't map to a Publication in CM #43

jhorsman opened this issue Feb 16, 2017 · 3 comments

Comments

@jhorsman
Copy link
Contributor

When someone requests a URL on a DXA webapplication which cannot be mapped to a publication, this error message is rendered: No matching Localization found for URL 'http://hostname/path'.

There are two issues with this

  • The error message is not styled; DXA has styled 500 error and 404 Not found pages, these are used for most error situations, but when the publication mapping does not work the webstite visitor gets this un styled error.
  • The controllers are never hit, so you cannot have a controller handling any unmapped URLs. For example, I have a site which does not have any publication mapped to the root url at http://hostname/, instead all publications are mapped to /en, /nl and so on. I would like to make a controller which redirects the visitor from the root URL http://hostname/ to http://hostname/en but the request will never hit my controller.

The problem is caused by Sdl.Web.Mvc.Statics.StaticContentModule. This module serves static content items like media. It needs the site localization to figure out if the request URL is a static URL. When the localization cannot be found it will return a 404 not found status with the exception message.

I think the StaticContentModule should not render this error message. It could silently fail, write a warning to the log like it does today, and continue. The request will then go to the routes, eventually be handled by the PageController (or my custom controller in my use case). The PageController will also not find the site localization, and it can return a static 404 not found just like it can serve a static 500 error.

@rpannekoek
Copy link
Contributor

Your idea to handle the unknown Localization error later in the process makes sense, but note that there are two work-arounds available:

1.Ensure that there is a mapping for http://hostname too in TTM (e.g. to some parent Publication which you don't really publish).
2. Implement your own "Unknown Localization Handler", i.e. a class which implements IUnknownLocalizationHandler and is registered in Unity.config. Such a handler will be invoked if a Localization cannot be resolved and it could return an HTTP 302 redirect.

@jhorsman
Copy link
Contributor Author

jhorsman commented Mar 1, 2017

I have run an experiment which does not throw an exception when there is no Localization set, but continues in a graceful way. https://github.com/jhorsman/dxa-web-application-dotnet/commits/localiation-experiment

@rpannekoek rpannekoek added this to the v2.0 milestone Mar 7, 2017
@rpannekoek
Copy link
Contributor

TSI-2341 (Internal issue ID for tracking purposes)

@rpannekoek rpannekoek changed the title No matching Localization found for URL 'http://hostname/' Support URLs which don't map to a Publication in CM Mar 7, 2017
@rpannekoek rpannekoek modified the milestones: v2.0, v2.2 Dec 18, 2018
@rpannekoek rpannekoek removed this from the v2.2 milestone Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants