开发者

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

开发者 https://www.devze.com 2023-01-04 10:26 出处:网络
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

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 si开发者_开发百科milar 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?


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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消