MS AJAX Objects Returning Unexpected Characters

Posted on 2009-02-17
Last Modified: 2013-11-26

I have a section of script in a Visual Studio 2008 generic HTTPModule that pulls script files (after being processed at the target server) from the servers into my script for adjustment to the resultant HTML before output to the end user.  The operant VB is included in the accompanying code snippet.

Problem: dashes and single quotes in the source files at the target server are rendering as rectangles (ý) in my final rendered output.

Some comments about the code snippet so it is easier to understand:

(1) ServerName is obtained from a database, and is of the form "" (i.e., this is the textual URL of the site I am sourcing content from).
(2) IPAddress is obtained from a database, and is the dedicated IP number for the site being targeted.
(3) AdjPathInfo is the full relative path of the page being sought (e.g., "xxx/yyy/zzz/pagename.asp").
(4) The line "app.Response.Write("<BASE HREF='" & baseurl & "'>")" is included so that hyperlinks with relative URL's will resolve to the targeted server (since the code the end user sees is really coming from my server, the absence of setting the BASE tag would result in broken links).
(5) The line "tmp = Replace(tmp, "src=""", "src=""http://" & IPAddress & "/")" is included so that images with relative SRC URL's are sourced from the targeted server instead of mine (same basic logic as in (4)).  The following line covers the case where "src" is capitalized.

If only one symbol were being replaced by rectangles, the solution would be simple (just perform a VB REPLACE operation).  The tricky thing here is that two symbols are being misrepresented (both dashes and single quotes), so getting the response stream to contain the correct source information in the first place seems necessary.

Thanks, Stu Engelman
Dim baseurl As String = "http://" & ServerName

app.Response.Write("<BASE HREF='" & baseurl & "'>")

Dim requesturl As String = "http://" & IPAddress & "/" & AdjPathInfo

Dim uri As New Uri(requesturl)

Dim request As HttpWebRequest = HttpWebRequest.Create(uri)

request.Method = "GET"

Dim response As HttpWebResponse = request.GetResponse()

Dim reader As New StreamReader(response.GetResponseStream())

Dim tmp As String = reader.ReadToEnd()


tmp = Replace(tmp, "src=""", "src=""http://" & IPAddress & "/")

tmp = Replace(tmp, "SRC=""", "SRC=""http://" & IPAddress & "/")


request = Nothing

response = Nothing

reader = Nothing

Open in new window

Question by:stuengelman
    1 Comment

    Accepted Solution


    Due to the delay, I had to raise a Microsoft ticket, and they resolved the problem.  I'll go ahead and accept this post as the solution.

    Thanks, Stu

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
    In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now