Orchard CultureSwitcher issue on "www" subdomain

Topics: General, Localization
May 7, 2015 at 6:30 AM

I have an issue with the Orchard CultureSwitcher, which might be based on my lack of knowledge on the finer details the development environment. I am using the Culture Switcher on this website, http://vinpro.co.za/, to switch between two languages. The switching between cultures work perfectly on the main domain, by using the "English" and "Afrikaans" links at the top of the page, but as soon as the website is accessed via http://www.vinpro.co.za/ then the switching does not work correctly and causes an infinite loop, which I will explain the reason for below.

In order to detect if a user is viewing the correct page, based on his culture, I do a language detection routine when a page is loaded and then trigger the opposite language culture using Javascript to "click" the actual button for the other language. (Example at bottom of post)

I had subsequently found a workaround whereby I added a redirect via IIS to redirect all traffic to the main domain. This worked but then the client said that they could no longer view the website because due an internal network setting their email comes through on the main domain and the website is accessed via the www subdomain. This brings me back to my original problem.

My question is, does anyone why the website Culture Switcher is working differently for the www subdomain. And secondly, how do I fix it?

Here is the code for how I do the automatic language detection and redirection. It might not be the best way but that is the only I could find to do it, and it works. :)

@using System.Web.Mvc;
@using System.Text.RegularExpressions;
@using Orchard.Mvc.Html;
@using Orchard.Localization.Models;
@using Orchard.Autoroute.Models;
@using Orchard.CultureSwitcher.Services;
var returnUrl = WorkContext.HttpContext.Request.Path;
returnUrl = returnUrl.Substring(1, returnUrl.Length - 1);
var current_lang = WorkContext.CurrentCulture;
var lang = "";
try {
    lang = Model.Content.Items[2].ContentItem.LocalizationPart.Culture.Culture;
} catch {}
try {
    lang = Model.ContentItem.LocalizationPart.Culture.Culture;
} catch {}
if (current_lang != lang) {
    var localizationContentService = WorkContext.Resolve<ILocalizableContentService>();
    AutoroutePart currentRoutePart;
    if (localizationContentService.TryGetRouteForUrl(returnUrl, out currentRoutePart)) {
        AutoroutePart localizedRoutePart;
        if (localizationContentService.TryFindLocalizedRoute(currentRoutePart.ContentItem, current_lang, out localizedRoutePart)) {
            returnUrl = localizedRoutePart.Path;
            using (Script.Foot()) {
                    $(document).ready(function() {
                        $(".container.page-content").append('<div id="redirect" class="popup-redirect"><h3>Language change detected</h3><p>Redirecting...</p></div>');
                            centered: true,
                            onLoad: function() {}
                        setTimeout(function() {
                            $('.lang-wrap .language').not('.active').click();
                        }, 3000);
May 7, 2015 at 6:47 AM
It's bad practice to have two host names for the same site. A permanent redirect from one to the other is not a workaround, it's what you should be doing. The email problems you had are a different issue that needs to be solved independently. The mail server record in the DNS is probably incorrectly configured.
May 7, 2015 at 6:59 AM
Hi Bertrand

Thanks for the reply.

As far as I can tell the reason why vinpro.co.za is inaccessible by client is because of the firewall blocking outbound traffic and uses that strickly for email access within the client's network. Are you saying that that is where problem should be solved and not on the website's side?
May 7, 2015 at 7:04 AM
May 7, 2015 at 7:16 AM

Thanks. Let me get back to client then. :)