Set as Homepage   Add to Favourites   Recommend   Contact



Menu

∙ Home
∙ Index (All Topics)
∙ About Me
∙ About This Blog
∙ Favourite Links
∙ RSS Feed

Categories

∙ ASP & PHP (1)
∙ HTML, XML and CSS (2)
∙ C / C++ (5)
∙ Java, JSP and Servlet (0)
∙ SQL-Oracle-PL/SQL (28)
∙ Operating Systems (1)
∙ OFF-Topic (8)

Popular Topics (Top 10)

∙ Decode Function in Oracle SQL (39385)

∙ Derin anlamlı sözler - Bunlar da Türkçe olanlar :) (28046)

∙ Turkcell Staj Günlüğü - 1: Introduction to Oracle (23416)

∙ Oracle performance analysis - Tracing and performance evaluation (21868)

∙ Differences between C and C++ (17521)

∙ Implicit vs. Explicit cursors - Performance analysis (10832)

∙ Turkcell Staj Günlüğü - 4: Transaction Management (9886)

∙ Turkcell Staj Günlüğü - 9: "SQL, PL/SQL and Java" ve "Redo Internals" (9174)

∙ Turkcell Staj Günlüğü - 2: Data Blocks, Extends and Segments (9083)

∙ Turkcell Staj Günlüğü - 3: Tablespaces, Datafiles and Control Files (9007)


Most Recent (Last 10)

∙ Matematik Asla Yalan Söylemez!

∙ Finding and Removing Loop on a Singly-Linked List

∙ Obfuscated C

∙ Is C a Vitamin? Yes, of course...

∙ Differences between C and C++

∙ Whence C? Why C? Whither C?

∙ Türkçe Karakterli Domain'lerin İç Yüzü

∙ Windows Source Codes

∙ Decode Function in Oracle SQL

∙ Hello World!


Recent Comments (Last 10)

∙ "tebrikler" By yasin on Turkcell Staj Günlüğü - 5: Startup, Shutdown

∙ "Gercekten Güzel Bir Çalışma" By Hüseyin Karabakla on Neden hazır blog'ları kullanmadım ki?

∙ "Konu paralelinde güzel bir özet ek okuma - " By TongucY on Oracle performance analysis - Tracing and performance evaluation

∙ "harika" By burak ozcan on Derin anlamlı sözler - Bunlar da Türkçe olanlar :)

∙ "Tebrikler" By Tarık Bayzın on Turkcell Staj Günlüğü - 1: Introduction to Oracle

∙ "Gayet Başarılı.." By Fahri ATES on Turkcell Staj Günlüğü - 1: Introduction to Oracle

∙ "Helal olsun" By ender onder on Turkcell Staj Günlüğü - 5: Startup, Shutdown

∙ "tebrikler.." By ender ondeer on Turkcell Staj Günlüğü - 4: Transaction Management

∙ "Adulation?" By fizikci on Matematik Asla Yalan Söylemez!

∙ "Rehberlik için çook teşekkürler" By Pınar Tanrıverdi on Kahin'e yolculuk nasıl başlamalı?


Archive (Last 12 Months)

∙ Feb, 2008 (4)
∙ Jan, 2008 (2)
∙ Dec, 2007 (1)
∙ Sep, 2007 (4)
∙ Aug, 2007 (9)
∙ Jul, 2007 (22)
∙ Jun, 2007 (3)
∙ Index (All Records)

Other Related Blogs

∙ Tom Kyte’s Blog
∙ Steven Feuerstein’s Blog
∙ Jonathan Lewis’s Blog
∙ H.Tonguç Yılmaz Oracle Blog
∙ Mennan Tekbir's Blog
∙ Hakkı Oktay’s Blog
∙ Osman Çam’s Blog

Stats

Total Topics
Total Topic Views
Total Comments
Unique Visitors
Total Visitors
: 45
: 341112
: 44

About this blog…
About this blog…
About Me
About Me
Favourite Links
Favourite Links
Neden hazır blog'ları kullanmadım ki?
Neden hazır blog'ları kullanmadım ki?
CSS is more powerful than you imagine
CSS is more powerful than you imagine
Turkcell Staj Günlüğü - 1: Introduction to Oracle
Turkcell Staj Günlüğü - 1: Introduction to Oracle
Turkcell Staj Günlüğü - 2: Data Blocks, Extends and Segments
Turkcell Staj Günlüğü - 2: Data Blocks, Extends and Segments
Kahin'e yolculuk nasıl başlamalı?
Kahin'e yolculuk nasıl başlamalı?
Turkcell Staj Günlüğü - 3: Tablespaces, Datafiles and Control Files
Turkcell Staj Günlüğü - 3: Tablespaces, Datafiles and Control Files
Turkcell Staj Günlüğü - 4: Transaction Management
Turkcell Staj Günlüğü - 4: Transaction Management
Image formats - Which to use when
Image formats - Which to use when
Turkcell Staj Günlüğü - 5: Startup, Shutdown
Turkcell Staj Günlüğü - 5: Startup, Shutdown
Turkcell Staj Günlüğü - 6: Oracle Architecture
Turkcell Staj Günlüğü - 6: Oracle Architecture
ASP - Locales and Codepages
ASP - Locales and Codepages
Oracle performance analysis - Tracing and performance evaluation
Oracle performance analysis - Tracing and performance evaluation
Oracle performance analysis - Autotrace workshop
Oracle performance analysis - Autotrace workshop
Oracle performance analysis - Runstats workshop
Oracle performance analysis - Runstats workshop
Oracle performance analysis - Tkprof workshop
Oracle performance analysis - Tkprof workshop
Some favourite quotes
Some favourite quotes
Derin anlamlı sözler - Bunlar da Türkçe olanlar :)
Derin anlamlı sözler - Bunlar da Türkçe olanlar :)
Turkcell Staj Günlüğü - 7: Concurrency and Consistency
Turkcell Staj Günlüğü - 7: Concurrency and Consistency
"Kurtuluş"un hikayesi
"Kurtuluş"un hikayesi
Turkcell Staj Günlüğü - 8: Statement Processing and CBO
Turkcell Staj Günlüğü - 8: Statement Processing and CBO
When a transaction begins?
When a transaction begins?
Implicit vs. Explicit cursors - Performance analysis
Implicit vs. Explicit cursors - Performance analysis
Turkcell Staj Günlüğü - 9: "SQL, PL/SQL and Java" ve "Redo Internals"
Turkcell Staj Günlüğü - 9: "SQL, PL/SQL and Java" ve "Redo Internals"
Affect of gathering table stats to decision of CBO
Affect of gathering table stats to decision of CBO
Bind is bad :) - An interesting case of bind variables fails
Bind is bad :) - An interesting case of bind variables fails
When the explanation doesn't sound quite right...
When the explanation doesn't sound quite right...
Turkcell Staj Günlüğü - 10: Import, Export ve SQL Loader
Turkcell Staj Günlüğü - 10: Import, Export ve SQL Loader
Turkcell Staj Günlüğü - 11: Autonomous Transactions ve Dynamic SQL
Turkcell Staj Günlüğü - 11: Autonomous Transactions ve Dynamic SQL
Difference between db block gets and consistent gets
Difference between db block gets and consistent gets
Object-Oriented Features of Oracle - Part 1: Native Datatypes vs. Object Datatypes
Object-Oriented Features of Oracle - Part 1: Native Datatypes vs. Object Datatypes
Object-Oriented Features of Oracle - Part 2: Object Types and Collection types
Object-Oriented Features of Oracle - Part 2: Object Types and Collection types
Object-Oriented Features of Oracle - Part 3: Object Tables, Object Views and REFs
Object-Oriented Features of Oracle - Part 3: Object Tables, Object Views and REFs
Examining show_space
Examining show_space
Turkcell Staj Günlüğü - 12: Partitioning
Turkcell Staj Günlüğü - 12: Partitioning
Hello World!
Hello World!
Decode Demo #1
Decode Demo #1
Decode Demo #2
Decode Demo #2
Decode Demo #3
Decode Demo #3
Decode Demo #4
Decode Demo #4
Decode Function in Oracle SQL
Decode Function in Oracle SQL
Windows Source Codes
Windows Source Codes
Türkçe Karakterli Domain'lerin İç Yüzü
Türkçe Karakterli Domain'lerin İç Yüzü
Whence C? Why C? Whither C?
Whence C? Why C? Whither C?
Differences between C and C++
Differences between C and C++
Is C a Vitamin? Yes, of course...
Is C a Vitamin? Yes, of course...
Obfuscated C
Obfuscated C
Finding and Removing Loop on a Singly-Linked List
Finding and Removing Loop on a Singly-Linked List
Matematik Asla Yalan Söylemez!
Matematik Asla Yalan Söylemez!
eXTReMe Tracker
ASP - Locales and Codepages
Category: ASP & PHP
Date: 13.07.2007 22:18:11


For most of the Turkish ASP developers, nationalizing the session is a common problem. Because, hosting is an expensive service in Turkey, and most of the developers hire hosting or dedicated servers from abroad, especially from American companies. But here the problem comes: International hosting companies has different customers from different countries. This forces them to use common regional setting, like currency format or date format. But for developers, this causes a problem when it comes to display a date on their pages, coming from server variables or database, or store a date value on database.

On ASP pages, the LCID variable saves us - the developers. With LCID property, you can switch to the desired regional settings for a session or page response. So, when we print the date coming from a server variable or function (like now()) or from database, it just prints in our regional format according to the LCID setting. Also, same problem arises when writing a date field to a database, the date value will be written according to our regional setting that we set for a session.

Before we proceed to codng part, here are the LCID values of ASP for countries: http://msdn2.microsoft.com/en-us/library/ms912047.aspx

We can set the LCID property of our session in two ways:

1- Modifying session's LCID property at the top of the page (In page directives):

The code to modify the LCID property is like follows:

<%@ LANGUAGE="VBSCRIPT" LCID=1055 %>

' Continuing the asp code
' ...

It is a good practice to have a "setting file" having the settings for all pages, -that contains setting LCID, setting Codepage (we will discuss below in this topic), setting "Charset", setting "Buffer" and setting cache-control parameters, and the parameters like this- and include it to the top of every page. I have a setting file like this:

<%@ LANGUAGE="VBSCRIPT" LCID=1055%>
<%
response.Charset="utf-8"
session.CodePage="65001"
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
Response.Buffer=True

' Database connection
Set conn = Server.CreateObject("ADODB.Connection")
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open Server.MapPath("path_to_db.mdb")
%>

You see my setting or header -whatever you name it- file contains all of the common session and response settings. And I include this file (let's say "settings.asp") to the top of all my web pages like this:

<!-- #include file="settings.asp"-->
<%
' the ASP codes ...

%>
<html>

<!-- the html codes ... -->

</html>

The important point is, you must include the file to the top of the pages, nothing (an ASP code or html code) must be written above. Because <%@ ... %> directive must be at the top of an ASP page.

2- Modifying LCID property between the code

You can modify the LCID property between the code. Here the example comes:

<%
Session.LCID = 1055
Dim curNumb
curNumb = FormatCurrency(125)
Response.Write (curNumb)
%>

But, I prefer setting the LCID on Page directive, at top of the page and not chage it during runtime. You will not usually need to change it at runtime.

What about the codepage and the character encoding?

The character encoding is another problem. When you store your string data on database is UTF-8 encoded, you will have problem to display it on your ASP page. Or, simply you will have a problem that you cannot understand why, on displaying Turkish characters. Also, when you are testing your ASP page on local, no problem about displaying your TR characters, but when you upload the file to host and run your ASP page (usually having DB access and reading string that has TR characters on it from DB) you have problem to display the character. The reason is, you have a host abroad, and your host's default codepage is set to standart latin (English) letters.

Like LCID property, you can set the codepage property in two ways.

1- In page directives:

<%@ LANGUAGE="VBSCRIPT" codepage=65001 %>

' Continuing the asp code
' ...

But, this will modify the codepage for only this response. To modify the codepage for whole session -that is better-, use the second way.

2- Between the code:

<%
Session.codepage = 1254
' or Response.codepage= 1254
Response.Write ("öçüğış")
%>

Note that 1254 is Turkish codepage and 65001 is Unicode(utf-8) codepage.

Setting Response.CodePage explicitly affects a single page, whereas Session.CodePage affects all responses in a session.

If Response.CodePage is not explicitly set in a page, it is implicitly set by Session.CodePage, if sessions are enabled. If sessions are not enabled, Response.CodePage is set by @CodePage, if @CodePage is present in the page. If there is no @CodePage in the page, Response.CodePage is set by the AspCodePage metabase property. If the AspCodePage metabase property is not set, or set to 0, Response.CodePage is set by the system ANSI codepage.

There can be only one codepage per response body, otherwise incorrect characters are displayed. If you set the codepage explicitly in two pages where one is called by the other with #include, Server.Execute, or Server.Transfer, usually the parent page decides the codepage. The only exception is if Response.CodePage is explicitly set in the parent page of a Server.Execute call. In that case, an @CodePage command in the child page overrides the parent codepage.

Literal strings in a script are still encoded by using @CodePage (if present) or the AspCodePage metabase property value (if set), or the system ANSI codepage. If you set Response.CodePage or Session.CodePage explicitly, do so before sending nonliteral strings to the client. If you use literal and nonliteral strings in the same page, make sure the codepage of @CodePage matches the codepage of Response.CodePage, or the literal strings are encoded differently from the nonliteral strings and display incorrectly.

If the codepage of your Web page matches the system defaults of the Web client, you do not need to set a codepage in your Web page. However, setting the value is recommended. If the codepage is set in a page, then Response.Charset should also be set. The codepage value specifies to IIS how to encode the data when building the response, and the Charset value specifies to the browser how to decode the data when displaying the response. The CharsetName parameter of Response.Charset must match the codepage value, or mixed characters will be displayed in the browser. Lists of CharsetName parameters and matching codepage values can be found on MSDN Web Workshop under the columns for Preferred Charset Label and FamilyCodePage.

The file format of a Web page must be the same as the @CodePage used in the page. Notepad enables you to save files in UTF-8 format or in the system ANSI format. For example, if @CodePage is set to 65001 (indicating UTF-8), the Web file must be saved in UTF-8 format. If @CodePage is set to 1252 (indicating English or German), the Web file must be saved in ANSI format on an English or German system. If you want to save a page in the ANSI format for a language other than your system language, you can change your default System Locale settings in Regional and Language Options in the Control Panel. For example, after you change your system locale to Japanese, any files you save in ANSI format are saved using the Japanese codepage and are only readable from a Japanese system locale.

If you are writing and testing Web pages that use different codepages and character sets (for example, if you were creating a multilingual Web site), remember that your test client computer must have the language packs installed for each language you want to display. You can install language packs from Regional and Language Options in the Control Panel.

Using Unicode charset is a good practice. I will write a different topic on using Unicode and advantages and importance of Unicode charset.

Please follow the blog, and comment on entries. Your comments are important.

Links & References

Comments

No comments posted yet.



© Copyright. All rights reserved. Designed by Bilal Hatipoğlu. RSS Feed  Valid W3C XHTML 1.0 Document  Valid W3C CSS Document