Language based content negotiation in web.api

What is the best way to support language-based content negotiation (Accept-Language header) in a new ASP.NET web application?

The new API has a nice way to support the negotiation of content across media types (see here ), but I couldn't find a pointer on how we could make content negatively related based on the language title.



source to share

3 answers

You can call directly FormatterSelector

to find out what you want. HttpMessageHandler

as @AlexanderZeitler pointed out is probably best suited for this at the site level. You can see a simple form for working with FormatterSelector

in WebApiContrib .

Hopefully this will become a new expansion point in a future release.



You can use the MessageHandler to validate the headers and change the accept header to match the type that the custom formatter can agree on.



If you set the UICulture and Culture to auto in the globalization element in web.config, ASP.Net will automatically set CurrentThread.CurrentUICulture and CurrentThread.CurrentCulture based on the Accept-Language header.

    <globalization uiCulture="auto" culture="auto"/>




All Articles