We recently upgraded our Ektron CMS400.NET 7.66
SP4 site to 8.01. Everything went smoothly except one
thing: The foreign language sites started failing. We had
used a fall-over method for our translated sites. For
example, if the german site was loaded, and german translated
content wasn't found, it would fall over to the english
content. This kept us from having to keep everything
translated, and kept the site cleaner.
After about a week of back and forth with technical support, I
got this email back:
Hi Ben,
I've spoken to my tech lead and it turns out you are seeing the
expected results, in the current version of the CMS. Previously,
the aliasing for different languages worked the way we discussed on
the phone, where if the content did not exist in the current site
language, the user would see the English content.
This was changed along the line because it takes the user out of
the "language experience" so to speak - if you are viewing the site
in French, and click on a link, the content should always be in
French. If that content doesn't exist in French, then you'll get
the 404.
I suspect that something is cached when you hit the page for the
first time, but every time after, the aliasing is working as
expected.
To avoid seeing the 404 errors, you would need to create the
content in each language. One option, if you are not actually
translating the content but would want users in other languages to
see English content, would be to create a content strategy which
would create the other-language content in the workarea upon
creating/publishing the English version.
I hope that explanation makes sense, and I apologize for the
confusion! Please let me know if you have any questions, or need
any additional information.
I was actually relieved, because then I knew something wasn't
broken. So all I needed to do was "fix" the aliasing module
to do what we wanted. Hope that it is clear... if the current
language isn't found, we manually set to 1033 (english) and try the
lookup again. Hope this helps anyone in the same boat.
So now we are running fine again. If
anyone is interested in how we are setting the languages.... I
included that below as well.
Here is the updated
UrlAliasingBase.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for UrlAliasingBase
/// </summary>
public class UrlAliasingBase
{
public static void ProcessUrl(HttpContext context)
{
//Check if this is a Asset request
if (Ektron.ASM.EkHttpDavHandler.Utilities.IsAssetFile(context) || Ektron.ASM.EkHttpDavHandler.Utilities.IsPrivateAssetFile(context) || Ektron.ASM.EkHttpDavHandler.Utilities.IsDavFile(context))
{
return;
}
//Skip workarea files
if (Ektron.Cms.UrlAliasing.UrlAliasCommonApi.IsWorkAreaFile(context))
{
return;
}
string fileExtension = string.Empty;
fileExtension = System.IO.Path.GetExtension(HttpContext.Current.Request.PhysicalPath);
if (fileExtension == string.Empty && !context.Request.Url.LocalPath.EndsWith("/"))
{
context.Response.Redirect(context.Request.Url.LocalPath + "/", true);
}
else
{
string targetUrl = Ektron.Cms.UrlAliasing.UrlAliasCommonApi.GetTargetUrl(context);
// Ben Longberg
// 1/28/2011
// HACK - Ektron no longer supports failing over to english content when translated content does not exist. (So this 'fixes' that)
// Ektron Blows.
//if empty check for english version
if (string.IsNullOrEmpty(targetUrl))
{
HttpCookie ecm = context.Request.Cookies["ecm"];
if (ecm != null && !string.IsNullOrEmpty(ecm["SiteLanguage"]))
{
ecm.Values.Remove("SiteLanguage");
ecm["SiteLanguage"] = "1033";
context.Response.Cookies.Add(ecm);
}
targetUrl = Ektron.Cms.UrlAliasing.UrlAliasCommonApi.GetTargetUrl(context);
}
// END HACK
if (!string.IsNullOrEmpty(targetUrl))
{
HttpContext.Current.Items["EkOriginalPath"] = HttpContext.Current.Request.Path;
context.RewritePath(targetUrl, false);
}
}
}
}
public static void InitializeCulture(HttpContext context)
{
string host = context.Request.Url.Host;
string appSettingKey = "language-" + host.ToLower();
string langType = AppSettingsUtility.GetKeyValue(appSettingKey, "-1");
HttpCookie ecm = context.Request.Cookies["ecm"];
if (!String.IsNullOrEmpty(context.Request.QueryString["LangType"]))
{
langType = context.Request.QueryString["LangType"];
}
else
{
if (langType != "-1")
{
if (ecm != null && !string.IsNullOrEmpty(ecm["SiteLanguage"]))
{
string currentLangType = ecm["SiteLanguage"];
if (currentLangType != langType)
{
ecm.Values.Remove("SiteLanguage");
ecm["SiteLanguage"] = langType;
context.Response.Cookies.Add(ecm);
}
//adding
//string currentLangType = ecm["langvalue"];
//if (currentLangType != langType)
//{
// ecm.Values.Remove("langvalue");
ecm["langvalue"] = langType;
context.Response.Cookies.Add(ecm);
//}
}
}
}
if (langType.Length > 0 && langType != "-1")
{
int lang = Convert.ToInt32(langType);
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
}
}