Thursday, 23th November 2006Changing IIS Regional Settings (for ASP Date, Time, Currency, etc)
How to safely change the regional settings for IIS.
I recently installed a new server and ran in to a problem I've incurred before - despite me hanging the servers regional settings to use U.K. formatting for dates and numbers, all my ASP pages were defaulting to U.S. regional settings. This is because Microsoft, in all their wisdom, decided that IIS (Internet Information Services) should take its regional settings from the IUSR account (an account whose password is generated by the server and not known to the server administrator - go figure).
Now many ASP purists will say that you should always set the locale of your application (e.g. website) anyway, forcing the server to acknowledge your region of choice - I agree. The problem is however, that I host websites I haven't created myself and also that many third party solutions and dreamweaver extensions) physically format the date how they want it - making regional settings ineffective.
Although I've seen all sorts of solutions out there, from registry changes to resetting the IUSR password, I hadn't found one I was entirely comfortable with. Firstly, registry setting changes always make me twitchy and secondly, resetting the password to the IUSR account can cause windows to permanently deny access to some IUSR recources.
The Solution
I took the obvious route instead and decided to find out how to get hold of the IUSR password that generated automatically and simply use the RUN AS option when firing up the regional settings dialogue to run them as the IUSR - so, down to business:
In order to allow the password to appear as anything other than asterisks you need to update the adsutil.vbs script (found in the AdminScripts folder in the Inetpub folder (often
C:/InetPub/AdminAcripts). Open the adsutil.vbs file in Notepad and search for "IsSecureProperty =
True", replace it with "IsSecureProperty = False" and save the file (keep it open so you can easily change it back afterwards).
Open a command prompt window (START > RUN > Type 'cmD' > OK)Browse to the InetPub/AdminScripts folder, for example:
C: (press enter)
CD \ inetpub\AdminScripts
To Retrieve the IUSR Password, enter this command:
cscript adsutil.vbs get w3svc/anonymoususerpass
Should return something like: anonymoususerpass : (STRING) "/fre5hJe7x"!39I"
To Retrieve the IWAM Password, enter this command:
cscript adsutil.vbs get w3svc/wamuserpass
Should return something like: wamuserpass : (STRING) "1like808!"
Now in the Control Panel, hold down the shift key and right click on the "Regional Settings" icon
Select "Run As" from the menu that appears
Login as the IUSR_yourServerName using the password retrieved above
Change the regional settings to whatever you need them to be for IIS and your done.
You may need to restart the server for the changes to take effect.
Don't forget to change the adsutil.vbs line back to read "IsSecureProperty = False"!
Comment On This Article
Article Comments
18
Bob, 16:53
12 September 2008
Michael - are you sure about the unsubscribe bug? I've doubled checked the code and the email I got when your comment was added had my email address embedded in it.
Can anyone else confirm one way or the other whether their own email is the one embedded in the unsubscribe link? (just putting your mouse over the link should tell you).
Thanks!
17
Bob, 16:48
12 September 2008
I agree with Ian & Michael - the only way to be 100% is to write functions to manipulate the date. This is really just good programming practice because you may well have to move the project to a server where you are unable to control the system defaults. As far as currencies are concerned, if you need to display a monetary value in multiple currencies then you still can't rely on the system currency as it doesn't calculate exchange rates. If you only need to display a single currency then write a custom function that uses formatNumber and appends the required currency symbol to it.
The following are a couple of date functions I use regularly - nothing special but here to copy and paste if you need 'em:
FUNCTION sqlSafeDate (unSafeDate) 'USED FOR INSERTING DATES IN TO A DATABASE sqlSafeDate = year(unSafeDate) & "/" & month(unSafeDate) & "/" & day(unSafeDate) END FUNCTION
FUNCTION formatLongDate (rawDate) IF ISDATE(rawDate) AND rawDate <> "" THEN dateDay = DAY(rawDate)
IF dateDay > 12 or dateDay < 21 THEN suffix = "th" ELSEIF dateDay < 13 or dateDay > 20 THEN SELECT CASE right(num,1) CASE "0" suffix = "th" CASE "1" suffix = "st" CASE "2" suffix = "nd" CASE "3" suffix = "rd" CASE ELSE suffix = "th" END SELECT END IF formatLongDate = WeekdayName(Weekday(rawDate)) & ", " & dateDay & suffix & " " & MONTHNAME(MONTH(rawDate)) & " " & YEAR(rawDate) END IF END FUNCTION
16
Michael Smith, 02:10
12 September 2008
Or you can do what I did, i just wrote a function to display the time / date in the way i wanted. Anytime I needed to display date/time I just called the function. Worked like a charm. I tried the regional settings, I have 2 servers with load balancing and SQL mirrored failover server, and no luck. This way was much less painless than all of that.
Also - someone should notify freshmango.com that their update to thread email notifications have a bug in them. When you try to unsubscribe from notifications it uses the person's email who last posted.
15
Ian Castillo, 10:03
11 September 2008
Hi All, We resolved this some time ago - here's what I learned: 1. Never ever rely on the system date for your ASP or ASP.NET applications. You should be using Cultures (allowing you to specify the location setting for your sites on a server, application, or page level), or LCID in the case of ASP. 2. If this is not an option for whatever reason (in our case, we had hardcoded the switching of DD and MM years ago, and we then migrated the software to a new server, so we needed a sooution which would not involve fiddling around with old code), the only surefire way to change the location setting permanently and properly is through the Registry. Unfortuantely this is dangerous because: a. you may make a mistake and cause major problems in your server b. Other services/applications may be relying on the date in its current format and changing it may cause them to behave erratically.
we ended up taking a risk and changing the registry - we were lucky as nothing went wrong.
Regards,
Ian
14
Dio, 09:53
11 September 2008
Hi Bob,
I know about the date-fix (I use a ISOdate function to rewrite all dates to that format) but the problem right know is currency. There are several sites that depend on inserting amounts using komma's (10,95) into the database. The have been migrated to a newer server which has the regional settings set to US instead of NL. If the regional setting are set to US it doesn't recognize the komma and puts 1095 into the currency field of the database. It's not really an option to rewrite all the code so this fix above is godsend if it weren't for the fact that is resets every 30 minutes or so.
13
Bob, 09:37
11 September 2008
Hi Dio,
You'd think Microsoft would have made this easier wouldn't you!! As far as the database handling dates are concerned, the format shouldn't matter for must things as long as you can get the date into the database in the correct format - to do that I use a simple one line function that converts dates to the following unambiguous date format: YYYY/MM/DD.
12
Dio, 02:59
11 September 2008
Hi,
first of all thanks for the fix. Unfortunately our server resets these regional settings for the IUSR every 30 minutes (or so). Using the LCID is a good way for use in pages but doesn't affect the way access databases handle numbers and dates.
11
Bob, 10:57
10 September 2008
Michael,
I must admit, people seem to have been having mixed success with this method - have you set the LCID in the page you are using the date? As a rule, I've started using specific date formatting functions for any dates I display now ( as I never know how a client has their server configured).
10
Michael Smith, 19:38
03 September 2008
I tried this also, everything worked fine, I ran_as the IUSR account but the format of the time I had changed stayed the same.
9
Bob, 21:59
13 August 2008
Hi Ian,
It sounds like you have a fairly unusual situation - while it may seem like curing the symptom as opposed to the illness, I'd recommend using custom date formatting anyway as for the future this makes your websites more portable anyway. There are numerous date formatting functions out there, when inserting dates in to a database from a system provided date, I ALWAYS use this simple function:
FUNCTION sqlSafeDate (rawDate) sqlSafeDate = year(rawDate) & "/" & monthname(month(rawDate)) & "/" & day(rawDate) END FUNCTION
You can simply rejig this to create a version that always writes the date in a specific format.
I recently had a client move to our web server that had a similar problem and basically the clash of required "defaults" made me wish we'd built all of our websites this way!
Presumably you have tried setting the LCID (http://www.w3schools.com/asp/prop_lcid.asp) or in your case whatever is the ASP.NET equivalent?
Sorry I can't be much more help but leaning ASP.NET is on my 'to do' list I'm afraid!
8
Ian Castilloing , 04:15
13 August 2008
Hi, first off, thanks for taking the time to respond. The dates we're referring to our dates that the user inputs (forms, date pickers, etc.). Since we're in Europe, the user enters a date in ddmmyyyy, we then strip this, switch dd and mm around to get mmddyyyy and this works fine in our code (since the server was set to US). On the new server, although the locale is US in the control panel, this is not working. In fact, a simple ASP.NET page which just displays the date and region info shows that it's set to ddmmyyyy and UK!!! I followed your instructions above, but to no avail! Funnily enough, when I run an classic ASP page with the response.write (Date()) command, I get the date in the correct (US) format!
IAN
7
Bob, 17:11
12 August 2008
Hi Ian,
Are your dates coming from a database or are you experiencing the same problem with dates being generated directly from code? Also - if you format a number using formatCurrency (or the .NET equivalent) what currency symbol are you being given?
As far as the IWAM account instructions, I believe at the time I was just compiling useful instructions together - so long ago since I wrote the article I must confess, things are hazy!
Cheers
Bob
6
Ian Castillo, 16:55
12 August 2008
Hi, we recently migratred all our websites/ASP.net applications to a new server and we're having issues with date time. On our original server, the regional settings were set to American format.
When a user enters a date in UK format (dd/mm/yyyy), we switch the month and date around so that the date works properly. Unfortunately, adter the switch to new servers, the dates are no longer working, even though th regional setting is correct.
I have also followed your instructions and the date for the IUSR acccount is in the correct format. Any other ideas?
FYI: when we uploaded an ASPX page which displays the date and time, it appears as dd/mm/yyyy, when we uploaded an ASP page that does the same, it displayed it as mm/dd/yyyy!
Also, how come you give instructions on retrieving the IWAM user account?
5
Bob, 21:35
17 September 2007
Jim - still not sure what I can do I'm afraid without logging in to your server to have a look - the tutorial is the only way I know of being able to retrieve the user name and password of the IUSR_ account. There may be other (simpler) ways to change the regional settings out there somewhere. Sorry I can't offer more help!
4
jim, 11:59
16 September 2007
Sorry,i think u didn't gt my previous msg.i'm trying to change IIS date time but not able to and i even followed ur tutorial but it says password or username invalid.i don know how to change IIS on my server.
3
Bob, 08:24
13 September 2007
Bill / Jim,
I'm not sure exactly what you want me to do really?
Are you having problem working through the tutorial?
- Home
- Services
- Portfolio
- Support
- About Us
- Contact Us
Login To Your AccountThursday, 23th November 2006Changing IIS Regional Settings (for ASP Date, Time, Currency, etc)
How to safely change the regional settings for IIS.
I recently installed a new server and ran in to a problem I've incurred before - despite me hanging the servers regional settings to use U.K. formatting for dates and numbers, all my ASP pages were defaulting to U.S. regional settings. This is because Microsoft, in all their wisdom, decided that IIS (Internet Information Services) should take its regional settings from the IUSR account (an account whose password is generated by the server and not known to the server administrator - go figure).
Now many ASP purists will say that you should always set the locale of your application (e.g. website) anyway, forcing the server to acknowledge your region of choice - I agree. The problem is however, that I host websites I haven't created myself and also that many third party solutions and dreamweaver extensions) physically format the date how they want it - making regional settings ineffective.
Although I've seen all sorts of solutions out there, from registry changes to resetting the IUSR password, I hadn't found one I was entirely comfortable with. Firstly, registry setting changes always make me twitchy and secondly, resetting the password to the IUSR account can cause windows to permanently deny access to some IUSR recources.
The Solution
I took the obvious route instead and decided to find out how to get hold of the IUSR password that generated automatically and simply use the RUN AS option when firing up the regional settings dialogue to run them as the IUSR - so, down to business:
In order to allow the password to appear as anything other than asterisks you need to update the adsutil.vbs script (found in the AdminScripts folder in the Inetpub folder (often
C:/InetPub/AdminAcripts). Open the adsutil.vbs file in Notepad and search for "IsSecureProperty =
True", replace it with "IsSecureProperty = False" and save the file (keep it open so you can easily change it back afterwards).
Open a command prompt window (START > RUN > Type 'cmD' > OK)Browse to the InetPub/AdminScripts folder, for example:
C: (press enter)
CD \ inetpub\AdminScripts
To Retrieve the IUSR Password, enter this command:
cscript adsutil.vbs get w3svc/anonymoususerpass
Should return something like: anonymoususerpass : (STRING) "/fre5hJe7x"!39I"
To Retrieve the IWAM Password, enter this command:
cscript adsutil.vbs get w3svc/wamuserpass
Should return something like: wamuserpass : (STRING) "1like808!"
Now in the Control Panel, hold down the shift key and right click on the "Regional Settings" icon
Select "Run As" from the menu that appears
Login as the IUSR_yourServerName using the password retrieved above
Change the regional settings to whatever you need them to be for IIS and your done.
You may need to restart the server for the changes to take effect.
Don't forget to change the adsutil.vbs line back to read "IsSecureProperty = False"!
Comment On This Article
Article Comments
Bob, 16:53
12 September 2008
Michael - are you sure about the unsubscribe bug? I've doubled checked the code and the email I got when your comment was added had my email address embedded in it.
Can anyone else confirm one way or the other whether their own email is the one embedded in the unsubscribe link? (just putting your mouse over the link should tell you).
Thanks!
Bob, 16:48
12 September 2008
I agree with Ian & Michael - the only way to be 100% is to write functions to manipulate the date. This is really just good programming practice because you may well have to move the project to a server where you are unable to control the system defaults. As far as currencies are concerned, if you need to display a monetary value in multiple currencies then you still can't rely on the system currency as it doesn't calculate exchange rates. If you only need to display a single currency then write a custom function that uses formatNumber and appends the required currency symbol to it.
The following are a couple of date functions I use regularly - nothing special but here to copy and paste if you need 'em:
FUNCTION sqlSafeDate (unSafeDate) 'USED FOR INSERTING DATES IN TO A DATABASE
sqlSafeDate = year(unSafeDate) & "/" & month(unSafeDate) & "/" & day(unSafeDate)
END FUNCTION
FUNCTION formatLongDate (rawDate)
IF ISDATE(rawDate) AND rawDate <> "" THEN
dateDay = DAY(rawDate)
IF dateDay > 12 or dateDay < 21 THEN
suffix = "th"
ELSEIF dateDay < 13 or dateDay > 20 THEN
SELECT CASE right(num,1)
CASE "0"
suffix = "th"
CASE "1"
suffix = "st"
CASE "2"
suffix = "nd"
CASE "3"
suffix = "rd"
CASE ELSE
suffix = "th"
END SELECT
END IF
formatLongDate = WeekdayName(Weekday(rawDate)) & ", " & dateDay & suffix & " " & MONTHNAME(MONTH(rawDate)) & " " & YEAR(rawDate)
END IF
END FUNCTION
Michael Smith, 02:10
12 September 2008
Or you can do what I did, i just wrote a function to display the time / date in the way i wanted. Anytime I needed to display date/time I just called the function. Worked like a charm. I tried the regional settings, I have 2 servers with load balancing and SQL mirrored failover server, and no luck. This way was much less painless than all of that.
Also - someone should notify freshmango.com that their update to thread email notifications have a bug in them. When you try to unsubscribe from notifications it uses the person's email who last posted.
Ian Castillo, 10:03
11 September 2008
Hi All,
We resolved this some time ago - here's what I learned:
1. Never ever rely on the system date for your ASP or ASP.NET applications. You should be using Cultures (allowing you to specify the location setting for your sites on a server, application, or page level), or LCID in the case of ASP.
2. If this is not an option for whatever reason (in our case, we had hardcoded the switching of DD and MM years ago, and we then migrated the software to a new server, so we needed a sooution which would not involve fiddling around with old code), the only surefire way to change the location setting permanently and properly is through the Registry. Unfortuantely this is dangerous because:
a. you may make a mistake and cause major problems in your server
b. Other services/applications may be relying on the date in its current format and changing it may cause them to behave erratically.
we ended up taking a risk and changing the registry - we were lucky as nothing went wrong.
Regards,
Ian
Dio, 09:53
11 September 2008
Hi Bob,
I know about the date-fix (I use a ISOdate function to rewrite all dates to that format) but the problem right know is currency. There are several sites that depend on inserting amounts using komma's (10,95) into the database. The have been migrated to a newer server which has the regional settings set to US instead of NL. If the regional setting are set to US it doesn't recognize the komma and puts 1095 into the currency field of the database. It's not really an option to rewrite all the code so this fix above is godsend if it weren't for the fact that is resets every 30 minutes or so.
Bob, 09:37
11 September 2008
Hi Dio,
You'd think Microsoft would have made this easier wouldn't you!! As far as the database handling dates are concerned, the format shouldn't matter for must things as long as you can get the date into the database in the correct format - to do that I use a simple one line function that converts dates to the following unambiguous date format: YYYY/MM/DD.
Dio, 02:59
11 September 2008
Hi,
first of all thanks for the fix. Unfortunately our server resets these regional settings for the IUSR every 30 minutes (or so).
Using the LCID is a good way for use in pages but doesn't affect the way access databases handle numbers and dates.
Bob, 10:57
10 September 2008
Michael,
I must admit, people seem to have been having mixed success with this method - have you set the LCID in the page you are using the date? As a rule, I've started using specific date formatting functions for any dates I display now ( as I never know how a client has their server configured).
Michael Smith, 19:38
03 September 2008
I tried this also, everything worked fine, I ran_as the IUSR account but the format of the time I had changed stayed the same.
Bob, 21:59
13 August 2008
Hi Ian,
It sounds like you have a fairly unusual situation - while it may seem like curing the symptom as opposed to the illness, I'd recommend using custom date formatting anyway as for the future this makes your websites more portable anyway. There are numerous date formatting functions out there, when inserting dates in to a database from a system provided date, I ALWAYS use this simple function:
FUNCTION sqlSafeDate (rawDate)
sqlSafeDate = year(rawDate) & "/" & monthname(month(rawDate)) & "/" & day(rawDate)
END FUNCTION
You can simply rejig this to create a version that always writes the date in a specific format.
I recently had a client move to our web server that had a similar problem and basically the clash of required "defaults" made me wish we'd built all of our websites this way!
Presumably you have tried setting the LCID (http://www.w3schools.com/asp/prop_lcid.asp) or in your case whatever is the ASP.NET equivalent?
Sorry I can't be much more help but leaning ASP.NET is on my 'to do' list I'm afraid!
Ian Castilloing , 04:15
13 August 2008
Hi, first off, thanks for taking the time to respond. The dates we're referring to our dates that the user inputs (forms, date pickers, etc.). Since we're in Europe, the user enters a date in ddmmyyyy, we then strip this, switch dd and mm around to get mmddyyyy and this works fine in our code (since the server was set to US). On the new server, although the locale is US in the control panel, this is not working. In fact, a simple ASP.NET page which just displays the date and region info shows that it's set to ddmmyyyy and UK!!! I followed your instructions above, but to no avail! Funnily enough, when I run an classic ASP page with the response.write (Date()) command, I get the date in the correct (US) format!
IAN
Bob, 17:11
12 August 2008
Hi Ian,
Are your dates coming from a database or are you experiencing the same problem with dates being generated directly from code? Also - if you format a number using formatCurrency (or the .NET equivalent) what currency symbol are you being given?
As far as the IWAM account instructions, I believe at the time I was just compiling useful instructions together - so long ago since I wrote the article I must confess, things are hazy!
Cheers
Bob
Ian Castillo, 16:55
12 August 2008
Hi, we recently migratred all our websites/ASP.net applications to a new server and we're having issues with date time. On our original server, the regional settings were set to American format.
When a user enters a date in UK format (dd/mm/yyyy), we switch the month and date around so that the date works properly. Unfortunately, adter the switch to new servers, the dates are no longer working, even though th regional setting is correct.
I have also followed your instructions and the date for the IUSR acccount is in the correct format. Any other ideas?
FYI: when we uploaded an ASPX page which displays the date and time, it appears as dd/mm/yyyy, when we uploaded an ASP page that does the same, it displayed it as mm/dd/yyyy!
Also, how come you give instructions on retrieving the IWAM user account?
Bob, 21:35
17 September 2007
Jim - still not sure what I can do I'm afraid without logging in to your server to have a look - the tutorial is the only way I know of being able to retrieve the user name and password of the IUSR_ account. There may be other (simpler) ways to change the regional settings out there somewhere. Sorry I can't offer more help!
jim, 11:59
16 September 2007
Sorry,i think u didn't gt my previous msg.i'm trying to change IIS date time but not able to and i even followed ur tutorial but it says password or username invalid.i don know how to change IIS on my server.
Bob, 08:24
13 September 2007
Bill / Jim,
I'm not sure exactly what you want me to do really?
Are you having problem working through the tutorial?
Bob
Jim, 07:25
13 September 2007
Please help me out
bill, 13:02
03 July 2007
thanks a lot!
Copyright © 2008 Fresh Mango Technologies. All Rights Reserved.
FreshMango.com is Coded Using Standards Compliant XHTML & CSS.