Nilay Parikh
Nilay Parikh

Reputation: 348

ASP.NET MVC (Content-language http header)

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.

Upvotes: 1

Views: 1695

Answers (2)

Marcelo Gondim
Marcelo Gondim

Reputation: 304

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);
}

Upvotes: 2

Andrei
Andrei

Reputation: 1061

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.

Upvotes: 4

Related Questions