久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='5SVtQ'><tr id='5SVtQ'><dt id='5SVtQ'><q id='5SVtQ'><span id='5SVtQ'><b id='5SVtQ'><form id='5SVtQ'><ins id='5SVtQ'></ins><ul id='5SVtQ'></ul><sub id='5SVtQ'></sub></form><legend id='5SVtQ'></legend><bdo id='5SVtQ'><pre id='5SVtQ'><center id='5SVtQ'></center></pre></bdo></b><th id='5SVtQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5SVtQ'><tfoot id='5SVtQ'></tfoot><dl id='5SVtQ'><fieldset id='5SVtQ'></fieldset></dl></div>
  • <small id='5SVtQ'></small><noframes id='5SVtQ'>

  • <tfoot id='5SVtQ'></tfoot>

          <bdo id='5SVtQ'></bdo><ul id='5SVtQ'></ul>
        <legend id='5SVtQ'><style id='5SVtQ'><dir id='5SVtQ'><q id='5SVtQ'></q></dir></style></legend>

        CurrentThread.CurrentUICulture 設置正確,但似乎被 as

        CurrentThread.CurrentUICulture is set correctly but seems to be ignored by asp.net(CurrentThread.CurrentUICulture 設置正確,但似乎被 asp.net 忽略)

          <legend id='zqYCx'><style id='zqYCx'><dir id='zqYCx'><q id='zqYCx'></q></dir></style></legend>
        1. <tfoot id='zqYCx'></tfoot>

                <i id='zqYCx'><tr id='zqYCx'><dt id='zqYCx'><q id='zqYCx'><span id='zqYCx'><b id='zqYCx'><form id='zqYCx'><ins id='zqYCx'></ins><ul id='zqYCx'></ul><sub id='zqYCx'></sub></form><legend id='zqYCx'></legend><bdo id='zqYCx'><pre id='zqYCx'><center id='zqYCx'></center></pre></bdo></b><th id='zqYCx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zqYCx'><tfoot id='zqYCx'></tfoot><dl id='zqYCx'><fieldset id='zqYCx'></fieldset></dl></div>
                  <tbody id='zqYCx'></tbody>

                <small id='zqYCx'></small><noframes id='zqYCx'>

                  <bdo id='zqYCx'></bdo><ul id='zqYCx'></ul>
                • 本文介紹了CurrentThread.CurrentUICulture 設置正確,但似乎被 asp.net 忽略的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在切換語言時,我正在努力從我的 in 文件夾中的資源文件中的正確 strings.txt 中獲取值.

                  我有一個 domain.com(英語)和一個 domain.nl(荷蘭語).然而,我使用哪個域以及如何設置 currentUICulture 似乎并不重要,向用戶顯示的語言總是相同的!

                  [default.aspx.vb]

                  部分類 _Default繼承 System.Web.UI.Page共享 rm 作為 ResourceManager = HttpContext.Current.Application("RM")Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 處理 Me.LoadLabel.Text = rm.GetString("homewelcome")結束子受保護的覆蓋子 InitializeCulture()SetLanguage(Request.Url.ToString)結束子公共共享子集語言(ByVal URL 作為字符串)Dim lang As String = ""如果 URL.Contains("www.domain.nl") 那么lang = "nl"ElseIf URL.Contains("www.domain.com") 然后lang = "en"萬一System.Threading.Thread.CurrentThread.CurrentUICulture = 新 System.Globalization.CultureInfo(lang)System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang)結束子結束類

                  [global.asax]

                  Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)應用程序(RM")=新資源管理器(字符串",Assembly.Load(字符串"))結束子

                  在我的 bin 文件夾中:

                  binstrings.txtbin lstrings.nl.txtbinenstrings.en.txt

                  我像這樣生成 dll:

                  resgen strings.txt strings.resourcesal/embed:strings.resources,strings.resources/out:strings.dllresgen nlstrings.nl.resourcesal/embed:nlstrings.nl.resources,strings.nl.resources/out:nlstrings.resources.dll/c:nlresgen enstrings.en.resourcesal/embed:enstrings.en.resources,strings.en.resources/out:enstrings.resources.dll/c:en

                  現在,所有文件似乎都已正確創建.

                  但是,當我訪問 www.domain.com 時,使用的是 binstrings.txt 中的值,而不是(如我所期望的那樣) binenstrings.en.txt 中的值

                  我在帶有 IIS7.5 的 Windows 7 上運行當我調試時,我發現在我的 InitializeCulture 方法中:

                  Protected Overrides Sub InitializeCulture()SetLanguage(Request.Url.ToString)結束子

                  當我檢查當前的 System.Threading.Thread.CurrentThread.CurrentUICulture.ToString 時,它等于en",所以似乎文化設置正確,只是不正確使用了strings.dll.

                  但是發生了更奇怪的事情:我的 default.aspx <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:lookingfor%>"/>

                  1. 當我接近 www.domain.nl(荷蘭域!)時,Literal1 控件顯示來自App_LocalResourcesdefault.aspx.en.resx"的值,而 rm.getstring 顯示來自 bin 的值strings.txt當我檢查當前 System.Threading.Thread.CurrentThread.CurrentUICulture.ToString 它等于nl"

                  2. 當我接近 www.domain.com(英文域!)時,Literal1 控件顯示來自App_LocalResourcesdefault.aspx.en.resx"的值,而 rm.getstring 顯示來自 bin 的值strings.txt當我檢查當前 System.Threading.Thread.CurrentThread.CurrentUICulture.ToString 它等于en"

                  這是怎么回事?

                  所以在使用 www.domain.nl 時,使用了錯誤的 strings.dll,但使用了正確的 .resx

                  解決方案

                  您可以使用 ResourceManager 的 GetString(string, CultureInfo) 重載來獲取正確語言的字符串.

                  順便說一句.global.asax 可能是設置 CurrentCulture 和 CurrentUICulture 的更好位置.

                  編輯根據彼得的要求提供代碼示例

                  全球.asax

                  首先,我會檢測和存儲文化:

                  Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)'在每個請求開始時觸發'作為 CultureInfo 的暗淡文化Dim uri As Uri = Request.Url如果 uri.ToString().Contains("nederlands") 那么文化 = 新 CultureInfo("nl-NL")ElseIf uri.ToString().Contains("polski") Then文化 = 新 CultureInfo("pl-PL")別的文化 = 新 CultureInfo("en-US")萬一Thread.CurrentThread.CurrentCulture = 文化Thread.CurrentThread.CurrentUICulture = 文化結束子

                  根據您想要做什么,它可能不是重載的最佳功能,在您的情況下,我相信 Session_Start 更好(也就是說,除非您想讓用戶能夠切換語言).
                  另一件事是,我沒有用域名測試它,我使用了查詢參數并且沒有正確驗證它們,但這只是為了舉例.

                  創建 App_LocalResources

                  我只能建議您使用 App_LocalResources,而不是實例化 ResourceManager 并手動編譯您的資源.您只需在解決方案資源管理器中右鍵單擊您的項目,選擇添加 -> 添加 Asp.Net 文件夾 -> App_LocalResources.

                  創建資源文件

                  創建適當命名的資源文件:Default.aspx.resx、Default.aspx.nl.resx 并將您想要本地化的內容添加到它們.在我的情況下是:

                  Default.aspx.resx(中性又名后備文化資源文件)

                  label1 一些標簽label2 其他一些標簽

                  Default.aspx.nl.resx(對不起我可憐的荷蘭語)

                  label1 Dit is een etiketlabel2 Dit is aner etiket

                  默認.aspx.pl.resx

                  label1 Jaka? tam labelkalabel2 Jaka? inna labelka

                  Default.aspx.vb(隱藏代碼)

                  在后面的代碼中,您可以像這樣以編程方式修改網頁的內容:

                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 處理 Me.LoadLabel2.Text = Me.GetLocalResourceObject("label2")結束子

                  出于許多原因,我不推薦這種方法(尤其是它不應該在頁面加載處理程序中使用),但有時需要它.

                  默認.aspx

                  終于到了我們漂亮(而且非常有用)的網頁:

                  <html xmlns="http://www.w3.org/1999/xhtml" ><head runat="服務器"><標題></標題></頭><身體><form id="form1" runat="server">

                  <asp:Label ID="Label1" runat="server" Text="<%$ Resources:label1 %>"></asp:Label><br/><asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></div></表格></身體></html>

                  如您所見,您可以使用以下表達式訪問資源:<%$ Resources:label1 %>.這將為您提供與 label1 資源鍵關聯的字符串.需要注意的重要事項: runat="server" 不是可選的.

                  HTH.您可能還想閱讀 關于 Asp.Net 本地化的教程.

                  Im struggling with gettings the values from the correct strings.txt in my resource files in my in folder when switching languages.

                  I have a domain.com (for English) and a domain.nl (for Dutch). It however doesnt seem to matter which domain I use and how I set the currentUICulture, the language shown to the user is always the same!

                  [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")
                      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
                  

                  In my bin folder I have:

                  binstrings.txt bin lstrings.nl.txt binenstrings.en.txt

                  I generate the dlls like so:

                  resgen strings.txt strings.resources
                  al /embed:strings.resources,strings.resources /out:strings.dll
                  resgen nlstrings.nl.resources
                  al /embed:nlstrings.nl.resources,strings.nl.resources /out:nlstrings.resources.dll /c:nl
                  resgen enstrings.en.resources
                  al /embed:enstrings.en.resources,strings.en.resources /out:enstrings.resources.dll /c:en
                  

                  Now, all files seem to be created correctly.

                  However, when I go to the www.domain.com, the values from binstrings.txt are used and NOT (like I would expect and desire), the values from binenstrings.en.txt

                  Im running on Windows 7 with IIS7.5 When I debugged I found that in my InitializeCulture method:

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

                  when I check for the current System.Threading.Thread.CurrentThread.CurrentUICulture.ToString its equal to "en", so it seems that the culture is SET correctly, its only that not the correct strings.dll is used.

                  But there's a more strange things going on: I have this in my default.aspx <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:lookingfor%>" />

                  1. When I aproach www.domain.nl (the Dutch domain!), the Literal1 controls displays the value from "App_LocalResourcesdefault.aspx.en.resx" and the rm.getstring shows me a value from binstrings.txt And when I check the current System.Threading.Thread.CurrentThread.CurrentUICulture.ToString its equal to "nl"

                  2. When I aproach www.domain.com (the English domain!), the Literal1 controls displays the value from "App_LocalResourcesdefault.aspx.en.resx" and the rm.getstring shows me a value from binstrings.txt And when I check the current System.Threading.Thread.CurrentThread.CurrentUICulture.ToString its equal to "en"

                  What is going on here?

                  So when using www.domain.nl, the WRONG strings.dll is used, but the CORRECT .resx

                  解決方案

                  You can use ResourceManager's GetString(string, CultureInfo) overload to get strings in correct language.

                  BTW. global.asax is probably the better place to set CurrentCulture and CurrentUICulture.

                  EDIT Providing code sample per Peter's request

                  Globabal.asax

                  For starters, I would detect and store culture:

                  Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
                      ' Fires at the beginning of each request '
                      Dim culture As CultureInfo
                      Dim uri As Uri = Request.Url
                      If uri.ToString().Contains("nederlands") Then
                          culture = New CultureInfo("nl-NL")
                      ElseIf uri.ToString().Contains("polski") Then
                          culture = New CultureInfo("pl-PL")
                      Else
                          culture = New CultureInfo("en-US")
                      End If
                  
                      Thread.CurrentThread.CurrentCulture = culture
                      Thread.CurrentThread.CurrentUICulture = culture
                  End Sub
                  

                  Depending on what you want to do, it might not be the best Function to overload, in your case I believe Session_Start is better (that is unless you want to give users an ability to switch language).
                  Another thing is, I didn't test it with domain names, I used query parameters and haven't validate them properly but it was just for the purpose of example only.

                  Create App_LocalResources

                  Instead of instantiating ResourceManager and compiling your resources manually, I can only suggest you to use App_LocalResources. You just need to right-click on your project in the Solution Explorer, choose Add -> Add Asp.Net Folder -> App_LocalResources.

                  Create resource files

                  Create appropriately named resource files: Default.aspx.resx, Default.aspx.nl.resx and add the contents you want to localize to them. In my case it was:

                  Default.aspx.resx (neutral aka fall-back culture resource file)

                  label1  Some label
                  label2  Some other label
                  

                  Default.aspx.nl.resx (Sorry for my poor Dutch)

                  label1  Dit is een etiket
                  label2  Dit is ander etiket
                  

                  Default.aspx.pl.resx

                  label1  Jaka? tam labelka
                  label2  Jaka? inna labelka
                  

                  Default.aspx.vb (code behind)

                  In code behind you can programmatically modify contents of your web page like this:

                  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                      Label2.Text = Me.GetLocalResourceObject("label2")
                  End Sub 
                  

                  For many reasons I would not recommend this method (especially it should not be used in page load handler), however it is sometimes needed.

                  Default.aspx

                  Finally we are at our beautiful (and very useful) web page:

                  <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" Text="<%$ Resources:label1 %>"></asp:Label>
                        <br />
                        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>    
                      </div>
                      </form>
                  </body>
                  </html>
                  

                  As you can see, you can access the resources with following expression: <%$ Resources:label1 %>. This will give you the string associated with label1 resource key. Important thing to note: runat="server" is not optional.

                  HTH. You may want to read the tutorial on Asp.Net Localization as well.

                  這篇關于CurrentThread.CurrentUICulture 設置正確,但似乎被 asp.net 忽略的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  extracting just page text using HTMLAgilityPack(使用 HTMLAgilityPack 僅提取頁面文本)
                  C# extracting data from XML(C# 從 XML 中提取數據)
                  Read a XML (from a string) and get some fields - Problems reading XML(讀取 XML(從字符串)并獲取一些字段 - 讀取 XML 時出現問題)
                  Reading large XML documents in .net(在 .net 中讀取大型 XML 文檔)
                  How to create folder in Google Drive using .NET API?(如何使用 .NET API 在 Google Drive 中創建文件夾?)

                        <i id='7Kuqm'><tr id='7Kuqm'><dt id='7Kuqm'><q id='7Kuqm'><span id='7Kuqm'><b id='7Kuqm'><form id='7Kuqm'><ins id='7Kuqm'></ins><ul id='7Kuqm'></ul><sub id='7Kuqm'></sub></form><legend id='7Kuqm'></legend><bdo id='7Kuqm'><pre id='7Kuqm'><center id='7Kuqm'></center></pre></bdo></b><th id='7Kuqm'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7Kuqm'><tfoot id='7Kuqm'></tfoot><dl id='7Kuqm'><fieldset id='7Kuqm'></fieldset></dl></div>

                      1. <legend id='7Kuqm'><style id='7Kuqm'><dir id='7Kuqm'><q id='7Kuqm'></q></dir></style></legend>
                          <tbody id='7Kuqm'></tbody>

                        <small id='7Kuqm'></small><noframes id='7Kuqm'>

                      2. <tfoot id='7Kuqm'></tfoot>
                        • <bdo id='7Kuqm'></bdo><ul id='7Kuqm'></ul>
                          • 主站蜘蛛池模板: 日韩欧美视频在线 | 91精品国产一区二区三区 | 国产精品99久久久久 | 久久久久99 | 欧美日韩精品一区二区三区蜜桃 | 紧缚调教一区二区三区视频 | 久久亚洲经典 | 精品1区 | 国产亚洲精品精品国产亚洲综合 | 欧美日韩精品区 | 超碰在线国产 | 国产福利精品一区 | 精品久久电影 | 国产精品一卡 | 日本视频在线 | 成人国产精品久久 | 日韩欧美在线免费观看 | 91社区视频| 久久亚 | a看片| 免费久| 一级看片免费视频 | 国产乱码一区 | 国产不卡在线观看 | 午夜a√ | 欧美日韩在线不卡 | 一区二区视屏 | 日韩成人免费视频 | 亚洲男人天堂 | 日本一区二区高清不卡 | 欧美一级片免费看 | 国产精品久久久久久久久久免费看 | 久久亚洲欧美日韩精品专区 | 亚洲综合久久久 | 欧美一区不卡 | 精品久久网 | 国产成人免费在线观看 | 国产三区精品 | 日韩视频一区 | 黄色片网站在线观看 | 黄色一级大片在线免费看产 |