Form post gives 404, when the home page url doesn't have the language


We develop a multilanguage website and use a language picker dropdown on the Root.cshtml to switch languages. The dropdown submit posts to the 'SetLanguage' action in the PageControllerBase.cs because it is common to all pages. 

@using (Html.BeginForm("SetLanguage", null, FormMethod.Post))
    @Html.DropDownList("selectedCountryCode", Model.Languages, new { onchange = "this.form.submit();" })

This all work fine except one scenario, when the home page url doesn't have the language.

E.g. - language picker can not find the action in the PageControllerBase, and give 404. - language picker works as expected. 

Is there a way to make home page url always have language set? 

Should I make a URL Rewrite rule to achieve this? 

Jun 22, 2021 9:16

Hi Helani,

This might be related how you have configured the website. I would assume you have not defined a language for the website / host(s)?

So if yo login to the admin view and navigate to the 'Config tab -> Manage Websites' and click your website, then view the 'Culture' setting for each host. If there is no culture set, then set the culture to your websites "default" aka master language, assuming english as default based on your example and save.

Making the assumption that there is no culture set currently and you can currently get the english content on the root page using both the and urls.

Jul 11, 2021 6:39

Hi Antti Alasvuo, yes you are spot on! It works after setting master language in Host name = *

Thank you!

Jul 12, 2021 4:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.