pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="bjp7rxf" 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="nlzttvp" 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")結(jié)束子受保護的覆蓋子 InitializeCulture()SetLanguage(Request.Url.ToString)結(jié)束子公共共享子集語言(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)結(jié)束子結(jié)束類

                  [global.asax]

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

                  在我的 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

                  現(xiàn)在,所有文件似乎都已正確創(chuàng)建.

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

                  我在帶有 IIS7.5 的 Windows 7 上運行當我調(diào)試時,我發(fā)現(xiàn)在我的 InitializeCulture 方法中:

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

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

                  但是發(fā)生了更奇怪的事情:我的 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 的更好位置.

                  編輯根據(jù)彼得的要求提供代碼示例

                  全球.asax

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

                  Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)'在每個請求開始時觸發(fā)'作為 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 = 文化結(jié)束子

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

                  創(chuàng)建 App_LocalResources

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

                  創(chuàng)建資源文件

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

                  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(隱藏代碼)

                  在后面的代碼中,您可以像這樣以編程方式修改網(wǎng)頁的內(nèi)容:

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

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

                  默認.aspx

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

                  <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 資源鍵關(guān)聯(lián)的字符串.需要注意的重要事項: runat="server" 不是可選的.

                  HTH.您可能還想閱讀 關(guān)于 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.

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

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

                  相關(guān)文檔推薦

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

                        <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="jpvd7dh" 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>
                          • 主站蜘蛛池模板: ISO9001认证咨询_iso9001企业认证代理机构_14001|18001|16949|50430认证-艾世欧认证网 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | 安徽控制器-合肥船用空调控制器-合肥家电控制器-合肥迅驰电子厂 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 真空上料机(一种真空输送机)-百科 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 山东风淋室_201/304不锈钢风淋室净化设备厂家-盛之源风淋室厂家 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 伸缩节_伸缩器_传力接头_伸缩接头_巩义市联通管道厂 | 光伏支架成型设备-光伏钢边框设备-光伏设备厂家 | 多功能真空滤油机_润滑油全自动滤油机_高效真空滤油机价格-重庆润华通驰 | 高硼硅玻璃|水位计玻璃板|光学三棱镜-邯郸奥维玻璃科技有限公司 高温高压釜(氢化反应釜)百科 | 电线电缆厂家|沈阳电缆厂|电线厂|沈阳英联塑力线缆有限公司 | 质检报告_CE认证_FCC认证_SRRC认证_PSE认证_第三方检测机构-深圳市环测威检测技术有限公司 | 依维柯自动挡房车,自行式国产改装房车,小型房车价格,中国十大房车品牌_南京拓锐斯特房车 - 南京拓锐斯特房车 | 防爆电机生产厂家,YBK3电动机,YBX3系列防爆电机,YBX4节防爆电机--河南省南洋防爆电机有限公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 12cr1mov无缝钢管切割-15crmog无缝钢管切割-40cr无缝钢管切割-42crmo无缝钢管切割-Q345B无缝钢管切割-45#无缝钢管切割 - 聊城宽达钢管有限公司 | 中医治疗皮肤病_潍坊银康医院「山东」重症皮肤病救治平台 | 欧盟ce检测认证_reach检测报告_第三方检测中心-深圳市威腾检验技术有限公司 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 橡胶接头_橡胶软接头_可曲挠橡胶接头-巩义市创伟机械制造有限公司 | 上海新光明泵业制造有限公司-电动隔膜泵,气动隔膜泵,卧式|立式离心泵厂家 | 细砂提取机,隔膜板框泥浆污泥压滤机,螺旋洗砂机设备,轮式洗砂机械,机制砂,圆锥颚式反击式破碎机,振动筛,滚筒筛,喂料机- 上海重睿环保设备有限公司 | ptc_浴霸_大巴_干衣机_呼吸机_毛巾架_电动车加热器-上海帕克 | 智能终端_RTU_dcm_北斗星空自动化科技 | 中宏网-今日新闻-财经新闻 | 西安标准厂房_陕西工业厂房_西咸新区独栋厂房_长信科技产业园官方网站 | 高压油管,液压接头,液压附件-烟台市正诚液压附件 | 达利园物流科技集团- | 上海道勤塑化有限公司| 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 科箭WMS仓库管理软件-TMS物流管理系统-科箭SaaS云服务 | 手持式浮游菌采样器-全排二级生物安全柜-浙江孚夏医疗科技有限公司 | 非甲烷总烃分析仪|环控百科 | (中山|佛山|江门)环氧地坪漆,停车场地板漆,车库地板漆,聚氨酯地板漆-中山永旺地坪漆厂家 | 东莞市超赞电子科技有限公司 全系列直插/贴片铝电解电容,电解电容,电容器 | 背压阀|减压器|不锈钢减压器|减压阀|卫生级背压阀|单向阀|背压阀厂家-上海沃原自控阀门有限公司 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 灰板纸、灰底白、硬纸板等纸品生产商-金泊纸业| 大功率金属激光焊接机价格_不锈钢汽车配件|光纤自动激光焊接机设备-东莞市正信激光科技有限公司 定制奶茶纸杯_定制豆浆杯_广东纸杯厂_[绿保佳]一家专业生产纸杯碗的厂家 | 防火板_饰面耐火板价格、厂家_品牌认准格林雅 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 |