ASP.net problem with Regional & Language Options (win2k3)

喜你入骨 提交于 2019-12-11 08:37:10

问题


I have a TextBox in an Asp.net form. there is a simple javascript witch separates each three digits in TextBox. it works fine when you enter data in TextBox. I used coma , for separating digits and used dot . as floating point character.

as I said every thing works fine when I am entering data in TextBox. but when the post-back occurs and saved data returns to client, every .(s) has been removed (for example 2.3 saved as 23 and digits in TextBox are separated by . instead of ,.

this problem occurs just in a specific server (windows server 2003 sp1) and works fine in other windows server 2003 (SP1)! I am experiencing this problem for first time!

But I think the problem is because of specific Regional & Language Options in the server. This server is joined to a domain controller. when I change the regional and language options to this set:

Decimal Symbol -> .

Digit Grouping Symbol -> ,

nothing changes.

when I check the following item after customizing settings :

Apply All Settings to the current user account and to the default user profile -> checked

when I restart the Server, It jumps out from domain and need to be re-joined to domain controller! and of-course nothing changes again!

Do you had this problem? any solution please!

I can not post code here, because the code is too complex and I am sure problem is not because of code because it is working every where unless the specified server.

EDIT

Also setting regional and language options for network service user may help to solve the problem. any body knows how can I do this ?


回答1:


Have you tried using the globalization tag in your web.config? This prevents you from running into trouble when multiple servers are configured differently (ie. different languagepacks).

<configuration>
   <system.web>
      <globalization 
         culture="en-US"
         uiCulture="en-US" />
   </system.web>
</configuration>



回答2:


After goofing around with a similar problem for WAY to long I did the following with the help of a number of clues (also found on StackOverFlow, StackOverFlow rocks by the way...)

The first thing I did was dump out what the server was actually thinking (Page_Load):

var dtInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo;
DisplayDebugInfo(String.Format(
    "Culture({0}/{1}), DateFormat(SD:{2},DS:{3})",
    System.Globalization.CultureInfo.CurrentCulture.Name,
    System.Globalization.CultureInfo.CurrentUICulture.Name,
    dtInfo.ShortDatePattern, dtInfo.DateSeparator));

Also on Windows 2003, I tried fixing the regional setting via the regular control panel but with no success.

I also tried setting the globalization settings in the web.config as mentioned in the other solution but with little effect.

It seems that once you start messing with the regional setting you can quickly get to the point where things are messed up. I decided to avoid messing with the registry and go for a code solution because then I would not have to worry when my code was released to production.

I added the following code to the base class for my page so that it would fix it everywhere. You could also place it in the Page_Load.

using System.Globalization;
using System.Threading;

// Fix the cultural settings...
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
culture.DateTimeFormat.DateSeparator = "/";
Thread.CurrentThread.CurrentCulture = culture;

Problem solved. For me anyway.



来源:https://stackoverflow.com/questions/5763311/asp-net-problem-with-regional-language-options-win2k3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!