My home page has couple of controller Action methods which are called through Jquery AJAX. These seem to work fine. As part of some research I enabled additional language in the CMS.
Now the action methods return 404 as it expects language indicator in the url (Ex: https://abc.com/en/ActionMethodName) .If I update the url in client side by adding this indicator then it works. I want to be able to update the url dynamically or at least default to /en version when nothing is passed from client side. If the AJAX url is https://abc.com/ActionMethodName I want it to redirect to english version.
I tried to use the solution mentioned here https://stefanolsen.com/posts/ensuring-the-right-ajax-content-language-using-a-filter-attribute/ but this still gives me 404. Any idea what I could be doing wrong here.
The solution in the linked blog post assumes that you call the action method using the default MVC URL format (/ControllerName/ActionName). This means you may need to add the default MVC route. Then you can provide the language code as a request header in the AJAX request.
If you want to keep the URL structure as it is, make sure you have specified a default language in the "Manage Websites" section. Make sure English is selected for the primary hostname of the website. Then English language will be used as default/fallback when your AJAX code does not include a language segment in the request URL.