Vb.net asp.net本地化\bin文件夹文件中文件中的文本

Vb.net asp.net本地化\bin文件夹文件中文件中的文本,vb.net,resources,localization,globalization,Vb.net,Resources,Localization,Globalization,切换语言时,我正在努力从my\bin文件夹中的资源文件的right strings.txt中获取值 [default.aspx.vb] Partial Class _Default Inherits System.Web.UI.Page Shared rm As ResourceManager = HttpContext.Current.Application("RM") Protected Sub Page_Load(ByVal sender As Object,

切换语言时,我正在努力从my\bin文件夹中的资源文件的right strings.txt中获取值

[default.aspx.vb]

Partial Class _Default
    Inherits System.Web.UI.Page

    Shared rm As ResourceManager = HttpContext.Current.Application("RM")

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label.Text = rm.GetString("homewelcome") '"Alles over trouwen, voor je perfecte bruiloft"
    End Sub

    Protected Overrides Sub InitializeCulture()
        SetLanguage(Request.Url.ToString)
    End Sub

    Public Shared Sub SetLanguage(ByVal URL As String)
        Dim lang As String = ""
        If URL.Contains("www.domain.nl") Then
            lang = "nl"
        ElseIf URL.Contains("www.domain.com") Then
            lang = "en"
        End If
        System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(lang)
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang)
    End Sub
End Class
[global.asax]

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        Application("RM") = New ResourceManager("strings", Assembly.Load("strings"))
    End Sub
在我的bin文件夹中,我有:

bin\strings.txt
bin\nl\strings.nl.txt
bin\en\strings.en.txt

我按如下方式生成DLL:

resgen strings.txt strings.resources
al /embed:strings.resources,strings.resources /out:strings.dll
resgen nl\strings.nl.resources
al /embed:nl\strings.nl.resources,strings.nl.resources /out:nl\strings.resources.dll /c:nl
resgen en\strings.en.resources
al /embed:en\strings.en.resources,strings.en.resources /out:en\strings.resources.dll /c:en
现在,所有文件似乎都已正确创建

但是,当我访问www.domain.com时,会使用bin\strings.txt中的值,而不会使用bin\en\strings.en.txt中的值


为什么?

我在.NET 4.0 Windows 2008计算机上尝试了您的代码片段。它按你所希望的那样工作


我唯一能想到的就是。。。我试过的电脑安装了Windows MUI。想知道这是否是一个因素吗?

好奇。。。www.domain.nl有效吗?我在Windows 7上运行,这里只有英语,所以我希望这部分至少有效。我进行了更多的调试,发现在mu InitializeCulture方法中:当我检查当前System.Threading.Thread.CurrentThread.CurrentUICulture.ToString是否等于“en”时,受保护的覆盖子InitializeCulture()SetLanguage(Request.Url.ToString)End Sub,因此似乎区域性设置正确,只是没有使用正确的strings.dll…这有助于进一步帮助我吗?:)但是还有更奇怪的事情发生:当我接近www.domain.com时,在我的default.aspx中也有这个,Literal1控件显示“App_LocalResources\default.aspx.en.resx”中的值,当我检查当前的System.Threading.Thread.CurrentThread.CurrentUICulture.ToString是否等于“en”,因此,文化设置似乎是正确的。因此,当使用www.domain.com时,使用了错误的strings.dll,但正确的.resx文件…对我来说似乎有点太不一致了!