Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If InStr(Request.Url.AbsoluteUri, "domain1") Then
Session("GlobStrings") = "Domain1"
ElseIf InStr(Request.Url.AbsoluteUri, "domain2") Then
Session("GlobStrings") = "Domain2"
End If
End Sub
Protected Overrides Sub InitializeCulture()
If Request.Form("DropDownList1") IsNot Nothing Then
Dim selectedLanguage As String = Request.Form("DropDownList1")
UICulture = Request.Form("DropDownList1")
Culture = Request.Form("DropDownList1")
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
End If
MyBase.InitializeCulture()
End Sub
<asp:Label ID="Label1" runat="server" Text='<%$ Resources: Domain1, Home_Text1 %>'></asp:Label><br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="en-GB">English</asp:ListItem>
<asp:ListItem Value="de-DE">Deutsch</asp:ListItem>
<asp:ListItem Value="es-ES">Espanol</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text='<%$ Resources: Session("GlobStrings"), Home_Text1 %>'>
<asp:Label ID="Label1" runat="server" Text='<%$ Resources: SomeCompany, Home_Text1 %>'></asp:Label><br />
<asp:Label ID="Label1" runat="server" Text='<%$ Resources: OtherCompany, Home_Text1 %>'></asp:Label><br />
Dim companyName As String = "OtherCompany"
Dim label1 As New Label
Session("companyName") = companyName
label1.Text = Me.GetGlobalResourceObject(Session("companyName"), "Home_Text1").ToString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblCopyrightYear.Text = Year(Now())
Dim sURL As String = Request.Url.AbsoluteUri
If InStr(sURL, "mrmc") Then
Session("Store_Brand") = "mrmc"
ElseIf InStr(sURL, "mtmc") Then
Session("Store_Brand") = "mtmc"
End If
ltWebsiteTitle.Text = Me.GetGlobalResourceObject(Session("Store_Brand"), "WebTitle").ToString
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ltBreadcrumbs_Home.Text = GetGlobalResourceObject(Session("Store_Brand"), "Breadcrumbs_Home").ToString
End Sub
<asp:Content ID="Content6" ContentPlaceHolderID="Breadcrumbs" Runat="Server">
<ul>
<li class="active"><asp:literal ID="ltBreadcrumbs_Home" runat="server"></asp:literal></li>
</ul>
</asp:Content>
Could not find any resources appropriate for the specified culture or the neutral culture. Â Make sure "Resources..resources" was correctly embedded or linked into assembly "App_GlobalResources.s1xeyevf" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Line 9: Â Â Â Â Â ltBreadcrumbs_Home.Text = GetGlobalResourceObject(Session("Sto re_Brand") , "Breadcrumbs_Home").ToStri ng
Partial Class globalisation
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If InStr(Request.Url.AbsoluteUri, "mrmc") Then
Session("Store_Brand") = "mrmc"
ElseIf InStr(Request.Url.AbsoluteUri, "mtmc") Then
Session("Store_Brand") = "mtmc"
End If
Label1.text = Me.GetGlobalResourceObject(Session("Store_Brand"), "Company").ToString
End Sub
Protected Overrides Sub InitializeCulture()
If Request.Form("DropDownList1") IsNot Nothing Then
Dim selectedLanguage As String = Request.Form("DropDownList1")
UICulture = Request.Form("DropDownList1")
Culture = Request.Form("DropDownList1")
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
End If
MyBase.InitializeCulture()
End Sub
End Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="globalisation.aspx.vb" Inherits="globalisation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="en-GB">English</asp:ListItem>
<asp:ListItem Value="de-DE">Deutsch</asp:ListItem>
<asp:ListItem Value="es-ES">Espanol</asp:ListItem>
</asp:DropDownList>
<%= Session("GlobStrings")%>
</div>
</form>
</body>
</html>
Protected Overrides Sub InitializeCulture()
If Request.Form("DropDownList1") IsNot Nothing Then
Dim selectedLanguage As String = Request.Form("DropDownList1")
UICulture = Request.Form("DropDownList1")
Culture = Request.Form("DropDownList1")
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage)
Thread.CurrentThread.CurrentUICulture = New CultureInfo(selectedLanguage)
End If
MyBase.InitializeCulture()
End Sub
Literal1.Text = Me.GetGlobalResourceObject(Session("MRMCStore_Brand"), "CompanyName").ToString
Literal1.Text = Me.GetGlobalResourceObject("mrmc", "CompanyName").ToString
If Not Request.QueryString("site") Is Nothing Then
HttpContext.Current.Session("MRMCStore_Brand") = Request.QueryString("site")
End If
Globalization automatically provides the correct language based on the user's computer settings (browser setting to be exact). Â Therefore, you should check for that, and get ASP to do the rest.
In Global.asax you should have something like this to check for the existence of a cookie/session etc value that sets the page culture:
Open in new window
Your application will then be smarter because it will detect language regardless of domain name.