views:

192

answers:

2

See http://pilot.whatpub.org/Guide/002000/Pub002687.htm and have a look at the source.

The text in the description ("Refurbished in 2005...") has been pasted from a Word document into a System.Web.UI.WebControls.TextBox and then saved into a database as unicode.

It's obviously got some non-ASCII characters in there that IE interprets strangely.

Now, I can pass the string through System.Web.HttpUtility.HtmlEncode and it converts the e-acute character in "cafe" to an HTML constant. Same happens with the "£" character (there isn't one in that example) so they look fine.

However, HtmlEncode doesn't do anything with the unusual quote character before "wine" so it ends still being displayed as that weird ‘ sequence.

Is there some other encoding function that would help?

Cheers, Rob.

+1  A: 

I'm not sure what part of the application you have control over.

Try setting the charset in the Content-Type to something to make the browser render them characters properly.

Content-Type: text/html; charset=ISO-8859-1

(BTW, the page renders correctly in Firefox.)

UncleO
I have access to all of it - the HTML is generated by www.whatpub.pub by VB.NET code so changing how it's generated is simple.
Rob Nicholson
That's browser compatability for you :-) Doesn't render in Chrome.
Rob Nicholson
+2  A: 

The page is served correctly in UTF-8, but no charset encoding is specified. Add

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

to the <head></head>, and you'll be fine.

BTW, the http header also lacks a charset definition:

$ HEAD http://pilot.whatpub.org/Guide/002000/Pub002687.htm
[...]
Content-Type: text/html
[...]
$

Change it to

Content-Type: text/html; charset=UTF-8

and things will work out.

sunny256
Setting the HTTP header correctly is a lot more important than the meta tag, but both should be set to make sure everything works cross-browser.
mercator
How do you modify the HTTP header? This is a static web page sat on a web server. Sure, it's generated from code but after that, it's a static web page. It's IIS that serves up the page when you type the URL into the browser. It's not generated on the fly from a database so I'm not sure how to set the HTTP header. Is it some setting on IIS? If it is, that might be problematic as it's hosted...
Rob Nicholson
@Rob\ Nicholson - Yes, IIS has to be configured to deliver the correct HTTP header. This link should explain how it's done: http://www.w3.org/International/O-HTTP-charset
sunny256
Thanks - I've added the meta tag and it now renders correctly in IE7 and Chrome. I'll still a bit concerned about the HTTP header bit though...
Rob Nicholson
@Rob\ Nicholson - I see you've added the meta tag to the HTML, and it looks fine in Firefox, Konqueror and Lynx. All modern browsers should be able to set the charset based on the meta tag, so there's hardly no crisis if the HTTP header is served as-is. BTW, nice campaign. :-) Didn't find any Guinness, though...
sunny256
Yeah - just done that and very glad it worked. Also included the System.Web.HttpUtility.HtmlEncode call as I'd like it to be as compatible as possible. Good to hear that modern browsers will work just fine with the meta tag as I doubt I'll convince WebHost4Life to change the HTTP header :-)No, you'll not find any Guinness mentioned there and you know full well why! LOL
Rob Nicholson