I am looking to build a site in ASP.NET. I need it to be in french and english with the domains setup like so:
en.mysite.com fr.mysite.com
I do not want to
My solution was setting the lang in the BeginRequest
in global.asax
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim lang As String = "es" ''//default
If Request.Url.ToString.ToLower.StartsWith("http://es.")
lang = "es"
ElseIf Request.Url.ToString.ToLower.StartsWith("http://en.") Then
lang = "en"
End If
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang)
Site.Idioma = lang ''//static variable that I use in other parts of the site
End Sub
Do not forget to set a redirect when the user hits www.mysite.com, using the user's browser language preference
Imports System.Globalization
Partial Class redirect_Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal s As Object, ByVal e As System.EventArgs) _
Handles Me.Load
Select Case Mid(Request.UserLanguages(0).ToString(), 1, 2).ToLower
Case "en"
Response.Redirect("http://en.mysite.com")
Case Else
Response.Redirect("http://es.mysite.com")
End Select
End Sub
End Class
As a side point, I recommend you to use http://www.mysite.com/en because it is better from the SEO perspective (If it is important to your site)