Hello Martin.
This is what i need!
But i dont know where i need to put this code, i didnt find any CMSSessionEvents options in the CMS. I tried to edit the CMSSessionEvents.cs file in App_Code/Handlers, but i get a lot of errors like:
CS1519: Invalid token 'switch' in class, struct, or interface member declaration
and if i comment the switch i get this error:
CS0103: The name 'IP2CountryHelper' does not exist in the current context
For this second error i suppose i need to add a using at the top, but i don't know what i need to add
This is my CMSSessionEvents.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.SettingsProvider;
/// <summary>
/// Global CMS session events
/// </summary>
public class CMSSessionEvents
{
/// <summary>
/// Fires upon the application start
/// </summary>
public static CMSHandler Start = new CMSHandler();
string ipAddress = HttpContext.Current.Request.UserHostAddress;
string currentCountryName = IP2CountryHelper.GetCountryByIp(ipAddress);
switch (currentCountryName)
{
case "SPAIN":
CMSContext.CurrentUser.PreferredCultureCode = "es-es";
break;
case "FRANCE":
CMSContext.CurrentUser.PreferredCultureCode = "fr-FR";
break;
case "BELGIUM":
CMSContext.CurrentUser.PreferredCultureCode = "fr-FR";
break;
case "CANADA":
CMSContext.CurrentUser.PreferredCultureCode = "fr-FR";
break;
case "GERMANY":
CMSContext.CurrentUser.PreferredCultureCode = "de-DE";
break;
case "RUSSIAN FEDERATION":
CMSContext.CurrentUser.PreferredCultureCode = "ru-RU";
break;
case "UNITED KINGDOM":
CMSContext.CurrentUser.PreferredCultureCode = "en-GB";
break;
case "UNITED STATES":
CMSContext.CurrentUser.PreferredCultureCode = "en-us";
break;
default:
CMSContext.CurrentUser.PreferredCultureCode= "en-GB";
break;
}
/// <summary>
/// Fires upon the application end
/// </summary>
public static CMSHandler End = new CMSHandler();
}
Thank you so much for your help!