Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MVC
Hi,
 
I am working on MVC4 project which has to be made Globalization.
 
i created a BaseController and overloaded ExeuteCore method, now i am inheriting my BasecController to HomeController, but it is not inheriting the BaseController i dont know why.
if i made this in MVC3 it is working. my project has to be MVC4. please suggest me some solution.
 
i made following code.
 

it is my BaseClass.
 
public class BaseController : Controller
    {
        protected override void ExecuteCore()
        {
            string cultureName = null;
            // Attempt to read the culture cookie from Request
            HttpCookie cultureCookie = Request.Cookies["_culture"];
            if (cultureCookie != null)
                cultureName = cultureCookie.Value;
            else
                cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages

            // Validate culture name
            cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe

 
            // Modify current thread's cultures
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
 
            base.ExecuteCore();
        }
 
    }
 
it is my HomeController inheriting BaseController.

public class HomeController : BaseController
   {
       public ActionResult Index() {
 
           return View();
       }
   }
 

but it is not working. suggest me some solution.
Posted 15-Feb-13 4:58am
Comments
Fred Flams at 15-Feb-13 10:06am
   
Hello, in your override of the ExecuteCore method, I would put the call to the base classe as the first line of the method, not the last
 
protected override void ExecuteCore()
{
base.ExecuteCore();
 
string cultureName = null;
// Attempt to read the culture cookie from Request
HttpCookie cultureCookie = Request.Cookies["_culture"];
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else
cultureName = Request.UserLanguages[0]; // obtain it from HTTP header AcceptLanguages
 
// Validate culture name
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
 

// Modify current thread's cultures
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100