Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 391199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:02:18+00:00 2026-05-12T16:02:18+00:00

I am getting crazy with the localization of an MVC application. After a recent

  • 0

I am getting crazy with the localization of an MVC application.

After a recent question of mine I have followed this approach:

  1. The language is stored in Session[“lang”]
  2. Each controller inherits from my own BaseController, which overrides OnActionExecuting, and in this method reads the Session and sets CurrentCulture and CurrentUICulture

This works great, until the Data Annotation Layer comes in. It seems like it gets called BEFORE the action itself is executed, and therefore it always gets the error messages in the default language!

The fields declarations go like this:

[Required(ErrorMessageResourceName = "validazioneRichiesto", ErrorMessageResourceType = typeof(Resources.Resources))]
public string nome { get; set; }

So, is there any reasonable place where I can put the call?

I initialize the Data Annotation Model Binder in my Controller constructor.

public CardController() : base() {
    ModelBinders.Binders.DefaultBinder =
    new Microsoft.Web.Mvc.DataAnnotations.DataAnnotationsModelBinder();
}

So, since Session is always null in the controller’s constructor, and the action override is called AFTER the data annotation has validated the fields, where can I possibly set the CurrentCulture and CurrentUICulture to get localized errors?

I tried putting the CurrentCulture and CurrentUiCulture in Application_* (e.g. Application_AcquireRequestState or Application_PreRequestHandlerExecute) seems to have no effect…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:02:19+00:00Added an answer on May 12, 2026 at 4:02 pm

    As the culture is a global user setting, I am using it in the global.asax.cs file in the Application_BeginRequest method.

    It does the work for me (using cookies) but the Session is also available there.

    EDIT:

    /by Brock Allen:
    http://www.velocityreviews.com/forums/t282576-aspnet-20-session-availability-in-globalasax.html/

    Session is available in PreRequesthandlerExecute.

    The problem is that your code is being executed for every request into the server, and some requests (like ones for WebResourxe.axd) don’t utlilize
    Session (because the handler doesn’t implement IRequireSessionState). So change your code to only access Session if that request has access to it.

    Change your code to do this:

    protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    {
        if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
            SetCulture();    
    }
    

    Anyway, not sure if it works with mvc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It will be a noob question, but i'm getting crazy with this. I've read
I'm getting crazy with this IE 7... ==> hhttp://neu.emergent-innovation.com/ Why does following function not
I am getting crazy over this error. Compiler is saying out of scope for
I have the following code and I'm getting crazy with calling an auto_increment id
Please help me to fix this issue (Im getting crazy now!), My project is
I would like to request some help, because I'm getting crazy I already have
This particular stuff is getting me crazy : Win [1365:707] Could not load the
I have a serious(it's getting me crazy) problem with LINQ to SQL . I
I'm getting crazy with .htaccess and rewrite rule. I'd like to understand how it
I'm getting crazy with a small problem here, I keep getting an error and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.