markzzz
markzzz

Reputation: 47945

Which Character encoding need I to set on my .NET web application?

Checking my website on W3C validator it says only this :

No Character encoding declared at document level

No character encoding information was found within the document, either in an HTML meta element or an XML declaration. It is often recommended to declare the character encoding in the document itself, especially if there is a chance that the document will be read from or saved to disk, CD, etc.

I know it is not so important, but I'm curios : which kind of meta tag/encoding I need to set on my .NET 4.0 web application? How can I know which encode .NET manage my data?

Upvotes: 0

Views: 186

Answers (2)

Lars Nyström
Lars Nyström

Reputation: 6373

You are utterly wrong when you say "it is not so important". If you do not specify your character encoding web browsers won't know how to display your document, so they'll guess. If you ever use any character not in the english language you're screwed. Actually, you might get screwed even if you just use english characters.

Here's a very famous blog post about character sets and character encodings: http://www.joelonsoftware.com/articles/Unicode.html

To answer your question: First you need to figure out which character encoding you're using. It's probably ISO-8859-1 or UTF-8. Then add this as the first line in your head-tag:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

That tag can be used in XHTML 1.0 and HTML 5, but not any later version of XHTML or HTML 4.

Upvotes: 5

muffel
muffel

Reputation: 7360

You have to add a tag like

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

to the head section of your page(s) / masterpage.

It does not have anything to do with .Net but with the encoding your .aspx pages are saved in (UTF-8 by default if they were created using Visual Studio").

Upvotes: 2

Related Questions