473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Encoding in ASP.NET sites

Is there a way to force an encoding in a asp.net site?
I have tried to save the pages in utf-8 encoding, with a lot of
succsess.
Letters like ÆØÅ (norwegian letters) are displayed when I do it this
way, but I dont want to have to go throu every page and save it in
utf-8 encoding. Is there a way I can change this in only one place?
I have tried to set the globalization tag in the web.config file, but
with no succsess.

Pål

Mar 29 '06 #1
6 1512
See http://msdn2.microsoft.com/en-us/lib...xf(VS.80).aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

<fo****@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Is there a way to force an encoding in a asp.net site?
I have tried to save the pages in utf-8 encoding, with a lot of
succsess.
Letters like ÆØÅ (norwegian letters) are displayed when I do it this
way, but I dont want to have to go throu every page and save it in
utf-8 encoding. Is there a way I can change this in only one place?
I have tried to set the globalization tag in the web.config file, but
with no succsess.

Pål
Mar 29 '06 #2
PL

If you enter text directly onto the pages in UTF-8 then your pages must be
saved in UTF-8, and you must specify the charset in the header such as:

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

this has nothing to do specifically with ASP.NET

It's the same in any encoding, the problem is that for some reason UTF-8 is
still considered "extra" instead of the default so most editors still save
text as ASCII only unless otherwise specified.

Although you don't necessarily have to save your scripts as UTF-8 to display
UTF-8, if you have unicode text being pulled from a database then alll you
need is to specify the default encoding for your app which is usually
already set to utf-8, you should also specify CODEPAGE="65001" in your @
Page declaration as well as provide the Content-Type meta tag so browsers
know what encoding the page is in.

In short:

o If you enter text directly onto your pages in UTF-8 your pages must be
saved as UTF-8
o If you pull stuff from database your pages does not have to be saved as
UTF-8 but you still have to specify the codepage and content-type.

PL.
<fo****@gmail.com> skrev i meddelandet
news:11**********************@u72g2000cwu.googlegr oups.com...
Is there a way to force an encoding in a asp.net site?
I have tried to save the pages in utf-8 encoding, with a lot of
succsess.
Letters like ÆØÅ (norwegian letters) are displayed when I do it this
way, but I dont want to have to go throu every page and save it in
utf-8 encoding. Is there a way I can change this in only one place?
I have tried to set the globalization tag in the web.config file, but
with no succsess.

Pål
Mar 29 '06 #3
Thus wrote PL,
If you enter text directly onto the pages in UTF-8 then your pages
must be saved in UTF-8,
Yes and...
and you must specify the charset in the header
such as:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
No, you don't have to. The response encoding is set as charset attribute
as part of the Content-Type HTTP header, which overrules META tags in every
civilized browser in use (YMMV).

META tags are also completely useless for true multibyte encodings like UTF-16,
at least as far as IE and Mozilla are concerned.
Although you don't necessarily have to save your scripts as UTF-8 to
display UTF-8, if you have unicode text being pulled from a database
then alll you need is to specify the default encoding for your app
which is usually already set to utf-8, you should also specify
CODEPAGE="65001" in your @ Page declaration as well as provide the
Content-Type meta tag so browsers know what encoding the page is in.


There's also the ResponseEncoding attribute, which uses friendly IANA names
instead of Win32 codepage identifiers. And of course there's the ContentEncoding
property in HttpResponse to set the encoding through code.

But all of this isn't required, *if* requestEncoding and responseEncoding
are set to UTF-8 in web.config, which is the default.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 29 '06 #4
Thus wrote fo****@gmail.com,
Is there a way to force an encoding in a asp.net site?
I have tried to save the pages in utf-8 encoding, with a lot of
succsess.
Letters like ÆØÅ (norwegian letters) are displayed when I do it this
way, but I dont want to have to go throu every page and save it in
utf-8 encoding. Is there a way I can change this in only one place?
I have tried to set the globalization tag in the web.config file, but
with no succsess.


VS2005's approach to choose an encoding for a source file is a bit bizarre.
The default encoding for ASP.NET pages with code files (which happens to
be the platform's default encoding on my machines) is different from the
one for inline code ASP.NET pages (UTF-8 for me) -- at least for C# projects.
AFAIK the same is true for Web Services code.

I don't really know of a way to enforce a certain encoding for a newly created
source file :-(

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 29 '06 #5
PL

I don't remember saying "required" anywhere but I agree I should have said
"should" instead of must. You didnt really find any factual errors so why
bother answering at all when what I said is actually the more correct way to
do it.

If you exclude the meta tag some browsers do behave strangely and you also
assume it will always be browsers reading it, sometimes the content could
even be saved for later display or built into a MHT file or whatever, the
tag *SHOULD* be there (satisfied?).

Don't just answer for the sake of being a besserwisser.

PL

"Joerg Jooss" <ne********@joergjooss.de> skrev i meddelandet
news:94**************************@msnews.microsoft .com...
Thus wrote PL,
If you enter text directly onto the pages in UTF-8 then your pages
must be saved in UTF-8,

<snip>
Mar 29 '06 #6
Thus wrote PL,
I don't remember saying "required" anywhere but I agree I should have
said "should" instead of must. You didnt really find any factual
errors so why bother answering at all when what I said is actually the
more correct way to do it.
"and you must specify the charset in the header such as:" reads like "required"
to me.

As I said, a META tag is useless for certain encodings. The correct way is
to specify requestEncoding and responseEncoding. You still may add a META
tag as a backup. I didn't say it's a bad thing in cases where the META tag
is recognized by a browser.
If you exclude the meta tag some browsers do behave strangely
Which?
and you
also assume it will always be browsers reading it, sometimes the
content could even be saved for later display or built into a MHT file
or whatever, the tag *SHOULD* be there (satisfied?).
It might help. It might be irrelevant. I spare you the details.
Don't just answer for the sake of being a besserwisser.


*shrug*

Return to line #1.
--
Joerg Jooss
ne********@joergjooss.de
Mar 30 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Klaus Alexander Seistrup | last post by:
Hi, After upgrading my Python interpreter to 2.3.1 I constantly get warnings like this: DeprecationWarning: Non-ASCII character '\xe6' in file mumble.py on line 2, but no encoding declared;...
12
by: Andrew DeFaria | last post by:
I am developing a database application in which I store usernames and passwords. Naturally I want to store the passwords in an encrypted form. However, just like you see in many web applications, I...
6
by: Jeroen De Brabander | last post by:
Hi, I have problems with XML Encoding concerning special characters like é and è. I have set the processing instruction to UTF-16 and the file is saved as UTF-16. The XML is valid and...
4
by: Jacek | last post by:
Hi! My app does quite a bit of work downloading large chunks of data from different web servers. One of problems I face is to provide approximate progress reports to users showing download...
2
by: hellrazor | last post by:
Hi there, We want to be able to encrypt the user ID and password within a URL, so when we send the URL via email, they'll be able to click said URL, and the aspx page should be able to decode it...
12
by: Manso | last post by:
Hi, Our sites need to support utf-8 so web.config has both request and response encoding set to utf-8. The problem is that Request.Querystring doesn't support this and we've tried to find a...
1
by: David | last post by:
Hi, I was looking for pointers as to why mail() would not send non standard ascii characters correctly. The web page has the correct encoding, and in the code this is set: $headers =...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.If the HTTP header contains Content-Length,am getting the content length as below:...
4
by: carljokl | last post by:
I am a C# .Net developer who has been involved with the development of a framework library used within our company. The framework is being developed against .Net version 2.0. One question I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.