I using this code for globalization and set language cookie for new users and that is a base class BaseController
. but it not executed at all. please help me.
using System;
using System.Web.Mvc;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Threading;
using System.Globalization;
namespace App1.Models
{
public class BaseController : Controller
{
private const string LanguageCookieName = "cookie_lang";
protected override void ExecuteCore()
{
var cookie = HttpContext.Request.Cookies[LanguageCookieName];
string lang;
lang = ConfigurationManager.AppSettings["DefaultCulture"] ?? "en-US";
if (cookie != null)
{
lang = cookie.Value;
}
else
{
var httpCookie = new HttpCookie(LanguageCookieName, lang)
{
Expires = DateTime.Now.AddYears(1)
};
HttpContext.Response.SetCookie(httpCookie);
}
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(lang);
base.ExecuteCore();
}
}
}
Here is a good article for multi language. It seems to me very good . http://afana.me/archive/2011/01/14/aspnet-mvc-internationalization.aspx/