title: MVC5 How to set language based on top level domain
body: <p>I have a single MVC5 site which is accessed via several different regional URLs. In my case .co.uk (for the UK), .de (for Germany) and .fr (for France).</p>
  
  <p>The site content is localised using RESX files and users can switch language via a cookie for persistence and a HttpModule which sets the asp.net thread locale based on the cookie (I used <a href="https://stackoverflow.com/questions/8922764/internationalization-with-asp-net-mvc3user-select-preferred-language-once-for-a">this approach</a>).</p>
  
  <p>I want the default language to be relevant to the top-level domain the user is accessing the site as. For example if a user is on .de, the default language should be de-DE. The user may choose to change the language in which case the default is overwritten, but it is very important that the default language is appropriate to the top-level domain (for users and search engines).</p>
  
  <p>How can I achieve this in MVC5? The best I have got to so far is using JavaScript to check the url, set the cookie and refresh the page, but i know this is nasty and there must be a better way.</p>
  
  <p>PS: Please note it is the top level domain that I want to drive this. I'm not using regional routing, for example <a href="http://whatever.com/DE" rel="nofollow noreferrer">http://whatever.com/DE</a> or <a href="http://whatever.com/EN" rel="nofollow noreferrer">http://whatever.com/EN</a></p>
  
  <p>PPS: I do not want to use the browser language detection feature either because that causes problems for search engines. i.e. it may cause the .de site to show in en-GB because that is what the search engine uses (or the search engine has no language so that is the default). If that happens the .de site will be treated as a duplicate of the .co.uk site which is never good for SEO</p>