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()
tmp = Replace(tmp, "src=""", "src=""http://" & IPAddress & "/")
tmp = Replace(tmp, "SRC=""", "SRC=""http://" & IPAddress & "/")
request = Nothing
response = Nothing
reader = Nothing