Sep 20, 2011 07:54 PM|rstrahl|LINK
Not sure, what you mean by best approach. If you switch your data to UTF-8, clients that receive the data and expect Windows-1252 will break unless they are automatically sniffing the encoding properly.
Changing the encoding is easy enough to do in web.config with:
One thing you can do is allow for a flag (querystring flag or request header) on the request to specify which encoding should be returned. Then in your actual code that generates output you can set Response.Encoding as needed in code.
var q = Request.QueryString["enc"];
if (!string.IsNullOrEmpty(q) && q == "utf8")
Response.ContentType = "text/html;charset=Utf-8";
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "text/html;charset=Windows-1252";
Response.ContentEncoding = Encoding.GetEncoding(1252);
This way you can serve responses both ways overriding whatever global settings are made to ASP.NET.
+++ Rick ---