We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

MS AJAX Objects Returning Unexpected Characters

Medium Priority
315 Views
Last Modified: 2013-11-26
Hello,

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 "sitename.com" (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()
response.Close()
tmp = Replace(tmp, "src=""", "src=""http://" & IPAddress & "/")
tmp = Replace(tmp, "SRC=""", "SRC=""http://" & IPAddress & "/")
app.Response.Write(tmp)
request = Nothing
response = Nothing
reader = Nothing

Open in new window

Comment
Watch Question

Hello,

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.