ASP.NET 全球化:Culture=“auto”中立文化崩溃的页面指令?
我遇到了使用内置全球化工具的 ASP.NET 应用程序崩溃的情况。
在具有 Culture="auto" 指令的 ASP.NET 页面上,使用中性文化作为浏览器语言(例如“zh-Hans”)的用户将产生以下异常:
文化“zh-Hans”是一种中立文化。它不能用于 格式化和解析,因此 不能设置为线程的当前线程 文化。
在 System.Globalization.CultureInfo.CheckNeutral(CultureInfo 文化) 在 System.Threading.Thread.set_CurrentCulture(CultureInfo 价值) 在 System.Web.UI.Page.set_Culture(字符串 价值) 在 ASP.somePage_aspx.__BuildControlTree(somePage_aspx __ctrl) 在 ASP.somePage_aspx.FrameworkInitialize()
有什么想法吗?通常,输入 Culture/UICulture 参数的垃圾似乎会被忽略,但这种情况会导致未处理的异常。
I'm running into a case where an ASP.NET application using the built-in globalization facilities is crashing.
On an ASP.NET page with the Culture="auto" directive, a user with a neutral culture as their browser language (such as "zh-Hans") will produce the following exception:
Culture 'zh-Hans' is a neutral culture. It cannot be used in
formatting and parsing and therefore
cannot be set as the thread's current
culture.at System.Globalization.CultureInfo.CheckNeutral(CultureInfo
culture)
at System.Threading.Thread.set_CurrentCulture(CultureInfo
value)
at System.Web.UI.Page.set_Culture(String
value)
at ASP.somePage_aspx.__BuildControlTree(somePage_aspx __ctrl)
at ASP.somePage_aspx.FrameworkInitialize()
Any ideas? Garbage fed into the Culture/UICulture parameters generally seem to be ignored, but this case is causing an unhandled exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也遇到了同样的问题,在把头撞在墙上一段时间后,我发现了答案就在我眼皮子底下。
我遇到的问题是不理解 CurrentCulture 和 CurrentUICulture 之间的区别。区别在于 CurrentCulture 用于格式化日期、数字并执行排序,CurrentUICulture 用于从资源中查找特定于文化的字符串。
我有一些代码看起来
应该是
当您开始尝试使用非特定区域性来格式化区域性特定项目时,您将得到 System.NotSupportedException。
I was having the same problem and after bonking my head against a wall for a while found the answer right under my nose.
The issue I had was in not understanding the difference between CurrentCulture and CurrentUICulture. The difference being CurrentCulture is used to format dates, numbers and perform sorting, CurrentUICulture is used to lookup culture specific strings from a resource.
I had some code that looked like
when it should be been
When you start trying to format culture specific items with a non-specific culture you will get the System.NotSupportedException.
首先,您可能会考虑在 <%@ Page %> 中设置 UICulture="auto" 和 Culture="auto"宣言。
现在,我在 .NET 4.0(测试版)安装中没有看到此重现,因此这可能是 .NET 3.5 中的产品错误。
这是了解中立文化以及 UICulture 和文化之间差异的绝佳资源:http://blogs.msdn.com/ddietric/archive/2008/02/05/yacvcp-yet-another-currentculture-vs-currentuiculture-post.aspx
希望这有帮助。
First off, you might consider setting UICulture="auto" as well as Culture="auto" in your <%@ Page %> declaration.
Now, I am not seeing this repro on my .NET 4.0 (beta) install, so this might be a product bug in .NET 3.5.
Here's a great resource for learning about neutral cultures and the difference between UICulture and Culture: http://blogs.msdn.com/ddietric/archive/2008/02/05/yacvcp-yet-another-currentculture-vs-currentuiculture-post.aspx
Hope that's helpful.
您不能在开始请求时设置文化吗? (注意:asp.net 请求可以在线程之间跳转,因此您也需要挂钩移动的线程。)
Can't you set the culture on begin request? (Note: asp.net requests can jump between threads so you need to hook into the thread moving as well.)