1

I'm developing content site (internationalised) using ASP.NET MVC. I use web.config (not clientbrowser setttings) to deliver region specific content.

<globalization culture="fr" uiCulture="fr" enableClientBasedCulture="false" />

I don't see ASP.net MVC framework is appending "Content-language" header automatically, is there a way to do that, and if yes than how. And if now than how can we put customised code most efficiently.

Regards.

2 Answers 2

4

In your controller, add:

Response.AddHeader("Content-language",
    Thread.CurrentThread.CurrentUICulture.Name);

you can apply it to all actions by creating a base class for all your controllers, and including this in overridden OnActionExecuting. Such as:

public class MyController : BaseController
{
    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        Response.AddHeader("Content-language",
            Thread.CurrentThread.CurrentUICulture.Name);
        base.OnActionExecuting(filterContext);
    }
}

Your controllers should then be changed to use MyController instead of BaseController as their base class.

Sign up to request clarification or add additional context in comments.

Comments

2

you can apply it to all actions by add this code to global.asax.cs

protected void Application_BeginRequest(object sender, EventArgs e)        
{
   Response.AddHeader("Content-language", Thread.CurrentThread.CurrentUICulture.Name);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.