Вопрос

My team is stuck on an issue with special characters that are causing problems only on the web server. We've tried to reproduce this bug when debugging locally but have so far been unsuccessful. We apprechiate any help to figure out why we don't get this error when running locally. What is the difference that makes it fail only in our Test environment?

We are trying to migrate a COM+ component to WCF and as a step in this we’re calling a WCF service directly from a classic ASP page by serizalizing/deserializing recordsets to XML.

Our problem arise when we try to save a special char like ‘, < or &’. We have special handling for the encoding of these that looks like this:

Function XMLEncode(byVal string)
    Dim tmp, i
    tmp = string
    For i = 160 to 255
        tmp = Replace(tmp, chr(i), "&#" & i & ";")
    Next
    tmp = Replace(tmp, chr(34), "&quot;") ' "
    tmp = Replace(tmp, chr(39), "&apos;") ' '
    tmp = Replace(tmp, chr(60), "&lt;") ' <
    tmp = Replace(tmp, chr(62), "&gt;") ' >
    tmp = Replace(tmp, chr(38), "&amp;") ' &
    XMLEncode = tmp
End Function

It seems works fine locally but when running the website in the Test environment we get error messages related to these characters.

We need hints on what else could cause this to fail on the server and not on our local machines.

Things we’ve tried:

  • Running the Web locally aimed at the Test environment database and WCF service, that should rule out any differences with the WCF or the data.
  • Compared the web.config used locally vs the one used in the Test environment without spotting a difference.
  • Compared the language locale setting for our local development computers vs the Test environment server without spotting a difference. It’s set to “English (United States)”.
  • Compared the request headers and document mode with the F12 Developer Tool in IE without spotting any difference in encoding or similar.

The web project is .NET 2.0, when we’re running locally it’s in IIS7.5 and when running on the Test environment server it’s IIS6. We are using MsXml2 to serialize/deserialize on the web end.

Thanks in advance

Это было полезно?

Решение

Thank you Paul that came up with the answer in the comment posted below the initial question.

Using ChrW instead of Chr solves the problem. The working code snipped below.

Function XMLEncode(byVal string)
    Dim tmp, i 
    tmp = string
    For i = 160 to 255
        tmp = Replace(tmp, chrw(i), "&#" & i & ";")
    Next

    tmp = Replace(tmp, chrw(34), "&quot;") ' "
    tmp = Replace(tmp, chrw(39), "&apos;") ' '
    tmp = Replace(tmp, chrw(60), "&lt;") ' <
    tmp = Replace(tmp, chrw(62), "&gt;") ' >
    tmp = Replace(tmp, chrw(38), "&amp;") ' &

    XMLEncode = tmp
End Function
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top