Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NETMVC
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 - 3:58

Comments
Fred Flams - 15 Feb '13 - 10:06
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 345
1 Sergey Alexandrovich Kryukov 338
2 Arun Vasu 315
3 Maciej Los 208
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,549
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid