我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp技巧/优化 > Using the Locale Identifier (LCID) (2)
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
ASP教程十一、调试ASP脚本(10-23)
在JSP中访问数据库大全(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

Using the Locale Identifier (LCID) (2) 

作者:佚名   来源:一亩三分地   点击:   日期:2007-03-22

In Part 1 we discussed how the Web server's regional settings (editable by the Administrator through the Control Panel's Regional Options icon) affect the output of VBScript's Format functions. In this part we'll look at using the Session.LCID property to change this default locale on a user-by-user (or Web page-by-Web page) basis! <br>
<br>
Setting the Locale ID on a User-by-User Basis:<br>
While the default locale setting dictates the output of the Format functions, what if you want to have the output differ based on the person visiting the page? (Perhaps you run a site where the user can customize the output or content presented, a site like My Yahoo! or any of the other customizable portals.) One option is to use the LCID property of the Session object (LCID stands for Locale Identifier). For example, you can specify the Locale for a particular user to be Estonian by using the following code: <br>
<br>
Session.LCID = 1061 'Estonian Locale ID&nbsp;&nbsp;<br>
<br>
<br>
Now, you may be wondering how in the world I knew that Estonian's LCID was 1061. The simplest way is to consult Microsoft's LCID table. This handy table contains a listing of all of the various locales and their associated IDs. By simply changing this locale ID, the output for the VBScript Format functions will change for the particular user. Using this property you can automatically have the Format functions' output change based on the user's LCID. <br>
<br>
One thing to be wary of is currency issues. For example, if I am running an English eCommerce site and have my Web server's regional settings set to English - United States by default, I may have some code that looks like this: <br>
<br>
Shoes cost: &lt;%=FormatCurrency(45.56)%&gt;&nbsp;&nbsp;<br>
<br>
<br>
Since, in this hypothetical example, I run an eCommerce site in the US, I mean that the cost for the shoes are 45 dollars and 56 cents. However, if set a user's Session.LCID property to, say, 2057 (English - United Kingdom), the shoes would appear to cost 45.56 pounds! Therefore, if you plan on altering the LCID settings I strongly encourage that you do not use the FormatCurrency function or, if you do, that instead of passing a hard-coded value into the function you pass in the result of some currency exchange rate calculation function: <br>
<br>
Shoes cost: &lt;%=FormatCurrency(ConvertFromDollars(45.56))%&gt;&nbsp;&nbsp;<br>
<br>
<br>
The ConvertFromDollar function would then consult the Session.LCID property to determine what currency we were converting our dollars to. (You would then need to use some component like iisCARTex to perform the actual currency conversion.) <br>
<br>
Setting the Locale ID on a Page-by-Page Basis:<br>
You can also specify the LCID for an entire ASP page instead of on a user-by-user basis. For example, if you had a Web page on your site that, for some reason, you wanted to always use the Hebrew formatting style (LCID 1037) you could do so via the @LCID directive. As with the other ASP directives (@LANGUAGE, @ENABLESESSIONSTATE, etc.), the @LCID directive must appear before any ASP or HTML code. For example, to set an ASP page's LCID to 1037 (Hebrew), we could use the following code: <br>
<br>
&lt;%@LCID=1037%&gt; <br>
<br>
<br>
or, if we wished to specify multiple directives, we could do: <br>
<br>
&lt;%@LANGUAGE=&quot;VBSCRIPT&quot; LCID=1037%&gt; <br>
<br>
<br>
That's all there is to it! <br>
<br>
Conclusion:<br>
In this article we examined how to set the default locale settings through the Regional Options icon in the Web server's Control Panel. This locale default determines how VBScript's Format functions produce their output. Any locale setting can be fully customized for a very unique look and feel for representing numbers, dates and times, and currencies. ASP also provides a Locale ID on both a user-by-user basis and a page-by-page basis. To specify a locale ID (LCID) for a particular user, set the Session.LCID property to the appropriate numeric ID. To set the LCID for a particular ASP page, use the @LCID directive. (For a listing of the various LCIDs and their respective values, check out the LCID table.) <br>
<br>
Happy Programming! <br>
<br>


文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·ASP中巧用Response属性 ·第六课:ASP脚本循环语句
·在 Web 页上使用条件数值格式 ·连接数据库查询手册(不仅仅适用于asp)
·警惕"给你的FileSystemObject对象加把锁" ·用ASP做全文检索

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。