How could ASP server-side code corrupt a smart quote ’?

▼魔方 西西 提交于 2019-12-24 01:33:29

问题


My company just converted many columns from varchar to nvarchar.

Now it seems that when we render a smart quote (i.e. ALT+0146 ’) to the screen and then send it back to the SQL Server 2000 database for persistence, the smart quote gets corrupted to - ’ -.

My Question:

How could ASP server-side code corrupt a smart quote ’ ?

EDIT: It appears that my question is similar to this one. Incidentally, Powerpoint content introduced the smart quote into the mix. However as I said before, I'm dealing with an ASP page, whereas the referenced question pertains to a PHP page.

EDIT: The server-side directive CODEPAGE=65001 makes the page render correctly, but it still posts content as 'Western European' on a Windows 2000 box. Does anyone know why?


回答1:


It looks like something is doing an implicit conversion between ANSI and Unicode (and choosing the wrong code page in the process). You may need to do the conversion manually and supply the correct code page. It's hard to say without seeing the code.




回答2:


Take a look at this:

http://support.microsoft.com/kb/232580

You may want to set your Code Page in the ASP so you don't get hokey characters.




回答3:


While you do need to tell the server which encoding to use, have you told the client what the page encoding is? If not, the client will happily post in whatever encoding the user last explicitly chose, or a system default encoding, which is likely to be western european on most US or Western European machines.

In your html, do you have something like this in your <head> ?

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

You can also ask the server to send this explicitly in your Response.Headers. Although I think it's a good idea to send it in the HTTP headers, it's helpful to include it in the HTML as well for people who decide to save the document locally for whatever reason.




回答4:


VBScript might mangle the Unicode characters; especially on older versions of IIS (i.e IIS 5.0 on Windows Server 2000).

In my case, a For Each construct was to blame.

Here's some example code that executes after a POST:

Response.Write Request.Form("selOptions")(0) ' A-OK! - Displays Unicode characters fine!  
For Each sOption in Request.Form("selOptions")
  Response.Write sOption ' Bad! Unicode characters are mangled!  
Next

As always, your mileage may vary.



来源:https://stackoverflow.com/questions/3087604/how-could-asp-server-side-code-corrupt-a-smart-quote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!