Thus wrote Leon_Amirreza,
i used an ASP.NET line of code to have server send charset in
ContentType but according to IIS Documentation these two lines of code
are equivalent:
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
CHARSET=windows-1251">
<% Response.Charset = "windows-1252" %>
That's plain wrong. First of all, Windows-1251 and Windows-1252 are different
encodings (that's a silly error in the IIS docs).
But more importantly, HTTP doesn't care about any HTML content, so specifying
a META tag works for clients that parse HTML (i.e. web browsers), but not
for HTTP intermediaries that process only HTTP headers. Setting a META tag
has no effect on HTTP headers in ASP.NET.
Next, all but forget about using the HttpResponse.Charset property -- that's
ASP programming.
The proper way of specifying a character encoding in ASP.NET is to either
1) use the default response encoding specified in your web.config's <globalization
/> element, UTF-8 by default
2) declare a ResponseEncoding in your page directive: <%@ Page Language="C#"
ResponseEncoding="ISO-8859-1" %>
3) declare a CodePage in your page directive: <%@ Page Language="C#" CodePage="28591"
%>
4) programmatically set the HttpResponse.ContentEncoding property: Response.ContentEncoding
= Encoding.GetEncoding(28591);
The only difference between 2) and 3) is that 2) relies on character encoding
(i.e. IANA) names, whereas 3) uses numeric Win32 codepage identifiers as
per
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_81rn.asp
All of the above implicitly set the HttpResponse.Charset to its appropriate
value (with one caveat -- see below). Vice versa, the same is *not* true.
Setting HttpResponse.Charset has no effect on the actual encoding applied
to the output stream. It's just a string that ends up in the Content-Type
header. Thus, you should never set Charset in your code (but see below**).
Morale of the story: ASP.NET sets the appropriate Content-Type header that
includes a charset attribute, unless you break stuff ;-)
For static content (i.e. that is directly served by IIS) none of the above
applies. See
http://www.w3.org/International/O-HTTP-charset for how to set
the appropriate Content-Type in these case.
**
When to set Charset: There's one esoteric case I'm aware of when you *do*
want to set HttpResponse.Charset in your code, and that's when you're using
UTF-16BE as response encoding. In this case, ASP.NET uses an invalid IANA
name, which is not recognized by all browsers. It sets "unicodeFFFE" instead
of "utf-16be".
Cheers,