Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm having some encoding issues with asp.net MVC 4 where certain characters like apostrophe appear as ’

I basically took a html file that someone made and made a new MVC app and put it into a view, but now I get issues with apostrophes and other characters appearing like, "he’s a cat".

I'm comparing opening the original html file on the disk in the browser, and running the MVC application which is in my local IIS. Same browser.

The HTML in the <head> section appears to be the same in both when I do view source:

<!DOCTYPE html>
<html class="no-js">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Cats</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="css/style.min.css">
    </head>

I'm at somewhat of a loss. Any ideas?

Edit: In firefox, going to View > Encoding shows both pages are in UTF-8.

like image 822
NibblyPig Avatar asked Dec 19 '22 18:12

NibblyPig


2 Answers

I've solved it, this is actually an issue with the way MVC was creating the HTML. I added the following to the web.config and it resolved the issue:

<globalization
      fileEncoding="utf-8"
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      culture="en-US"
      uiCulture="en-US"
    />

under <system.web>

like image 112
NibblyPig Avatar answered May 03 '23 07:05

NibblyPig


That's the character output when a right-single-quote is sent in ISO-8859-1 rather than UTF-8. In the head you're specifying ISO-8859-1 encoding so this is being misinterpreted. Your options are to use the HTML encoded value &rsquo; or, as you've seen yourself, change your encoding to UTF-8.

like image 23
Erik Noren Avatar answered May 03 '23 06:05

Erik Noren