Best practices for multi language site across different sub domains

前端 未结 3 1179
遇见更好的自我
遇见更好的自我 2021-01-13 19:27

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

相关标签:
3条回答
  • 2021-01-13 19:57

    As I understand correctly you want to place all files in the root directory but use subdomains for different languages.

    I think that en.mysite.com and fr.mysite.com must be just aliases and should tell asp.net application what language to use. You can change culture settings with code. It is well-described here.

    But from my point of view it is a better way to provide language settings on the main domain with some default language and ability to swith between languages. And if user advice to change language - he will just click one link. Language settings шт this case can ne stored anywhere (user profile, cookie, session, database if registered user etc.).

    0 讨论(0)
  • 2021-01-13 20:04

    If I'd be implementing this, I'd do this: map the en.mysie.com to www.mysite.com/page?lang=en map the fr.mysite.com to www.mysite.com/page?lang=fr

    and then in master page, set your language according to the param using globalization, and asp.net pages will automatically served in that language if they find correct app_localresource file with the same language code.

    Hope this helps

    0 讨论(0)
  • 2021-01-13 20:16

    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)

    0 讨论(0)
提交回复
热议问题