Dev Notes

Suspended Indefinetly...

News

<script type="text/javascript"><!-- google_ad_client = "pub-9887566656700242"; google_ad_width = 120; google_ad_height = 600; google_ad_format = "120x600_as"; google_ad_type = "text"; //2006-12-28: Savvy google_ad_channel = "6620623950"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <script type="text/javascript"><!-- google_ad_client = "pub-9887566656700242"; google_ad_width = 120; google_ad_height = 60; google_ad_format = "120x60_as_rimg"; google_cpa_choice = "CAAQxZqazgEaCMOiwb9yonQWKIHD93M"; google_ad_channel = ""; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

Favourites

Friends

India MVP & CS

My Blog Roll

Publicity

Default Encoding for ASP.NET ???

What is the default encoding used by ASP.NET ? Very trivial question huh ;-)

I found this as one of the most ignored thing in Web Application developement using ASP.NET
by any developer. Since VS.NET does a smart job by setting up a default encoding in web application
configuration, they need to bother about it....until unless they get a problem with 'characters' display
somewhere.

Today one of my buddy has got one weird problem with Japanese characters display while
exporting the reports to excel. It means somewhere the encoding set by VS.NET at application level
was overriden explicitly and Response was formed with the overriden encoding to the stream.

I tried to dig more in to this and found some interesting stuff here and here

ASP.NET's default encoding will be "iso-8859-1" (Western Europe) for both Response and Request.
i.e.. If Response/Request encoding is not specified in a machine.config or web.config file, encoding defaults to the
machine's Regional Options >> locale setting.

But Visual Studio.NET creates a section called <Globalization> and creates a default value "utf-8" to override the actual response/request encoding defaults. This makes our life happy enough to ignore the crux of encoding for our application.

<configuration>
   <system.web>
      <globalization
         requestEncoding="utf-8"
         responseEncoding="utf-8" />
   </system.web>
</configuration>

You can find more on this section here

Posted: Jan 19 2005, 04:16 PM by sudhakar[mvp] | with 8 comment(s)
Filed under:

Comments

shadow said:

Thanks a lot!

It worked!

I had problems with some characters too, now they're gone.

But it wasn't enough. For me worked:

<globalization requestEncoding="UTF-8" responseEncoding="UTF-8" fileEncoding="UTF-8" responseHeaderEncoding="UTF-8" />

# August 28, 2009 10:21 AM

Sagee said:

Thanks, Shadow, your addition saved my a very long night

# October 5, 2009 2:42 PM

ravi said:

these settings do not seems to help chinese characters. I had to use GB18030 to make it work. Any inputs?

# October 23, 2009 6:17 AM

Ashish said:

In my web.config file under globalization tag we have mentioned as UTF-8 encoding format. But in some of my pages i have to use iso-8859-1 (i.e. 28591) encoding format.

At the page level i able to set the encoding format iso-8859-1 but it is nt working out. And i cann't change in the web.config file as I don't knw where all it will effect in the entire application.

Please help!!! It's very urgent

Using VS 2005 and Framework 2.0

# December 9, 2009 1:04 AM

Alex said:

Thanx... this success for me too.

# April 13, 2010 6:07 PM

BMoshe said:

Ashish, I'm just guessing you use Response.Flush in your code. If so, know that it clears the ContentEncoding header and that might lead to such a problem.

# July 2, 2010 6:53 PM

rizasirman2 said:

I'm trying to create a vcard responded page. But none of these work for me :(

# December 20, 2010 9:51 AM

duudeman said:

Thanks for this information. It helped me solve easily an issue with character encoding when saving data entered on a web form to MySQL database.

# March 13, 2011 5:04 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)