0
votes

I'm trying to echo out a url in my classic ASP (JavaScript) pages. I have a little function to append a query string to the URL and echo it. My problem is that my string is being modified before being output; the protocol is changed to match the current protocol (http / https) and the subdomain is also changed (www or nothing). I don't want this to happen.

Here's my function that I'm using to append the query string:

function writeUrl(langcode, url)
{
    if(url.indexOf('?')==-1)
    {
        url = url + '?lang=' + langcode;
    }
    else
    {
        url = url + '&lang=' + langcode;
    }
    Response.Write(url);
}

Pretty simple, no? This function is included in the top of the page in question like this:

<!-- #include virtual="/inc_url.asp" -->

Lastly, in the page itself, I call the function. The 'lang' attribute is a 2-letter string.

<% writeUrl(lang, 'http://www.example.com/somepage'); %>

On visiting http://example.com/somepage?lang=fr I would have expected the above code to echo this:

http://www.example.com/somepage?lang=fr

However, I get any of the four following values, each one matching up with the URL I'm visiting:

Http://example.com/somepage?lang=fr
https://example.com/somepage?lang=fr
http://www.example.com/somepage?lang=fr
https://www.example.com/somepage?lang=fr

Can anyone point out somehing I'm missing? I'd like the URL to be output without that kind of modification: I want to use it for rel=canonical.

And no, re-writing it in .net is not a possibility.


New information - Even the URL when hard-coded into the html, even in a comment is changed. So, if I put <!-- http ://www.example.com/ --> into the html, then when I access it from https://example.com, it has been re-written as <!-- https ://example.com -->. This seem to confirm it's something down-stream. Any more ideas? (spaces added above so I don't exceed max number of hyperlinks).

3
Do you have a public-facing page where we can see this?Martijn
I'm under an NDA for this site, unfortunately. However, it's exactly as I mention above - if I go to example.com/somepage?lang=fr then that is the URL that's echoed, rather than the one I've specified in the code.JasonC
You did give me an idea, though. If the URL does not relate to the current URL (if it's for another domain), then it behaves as expected - as I want it to, without modifying the protocol or subdomain. So it only happens when the URL can access the current page. Unfortunately, that doesn't help me...JasonC
Are you using a load balancer, or is there any other layer between your web server and your browser? Nothing that could tinker with the page’s contents? Does the generated link really look like that when you view the source? What does Fiddler report?Martijn
It's definitely being output as I mention above in the source. As for a load balancer or anything else, I don't know - I don't have control of the server. It may be difficult for me to find out too: politics :o(JasonC

3 Answers

1
votes

What if you include it using <script runat="server" src="/inc_url.js"></script> instead of the <!-- #include virtual="/inc_url.asp" -->?

This would mean that it should be turned into a JS-only script file, so no <% %> tags, or <script /> tags.

0
votes

The server must be running some alternative ASP (as Chili!Soft ASP) or have some post-Processor or firewall that altered the bits being outputed.

You can try to fool the system:

Option 1. Try writing the url in two parts

 response.write "http://www.exa"
 response.write "mple.com/somepage?lang=fr"

Option 2. Write the url in the client using javascript

response.write "<SCRIPT TYPE='text/javascript'>"
response.write "  document.write('http://www.exa' + 'mple.com/somepage?lang=fr')"
response.write "</SCRIPT>"

(you can write letter by letter for maximum protection)

Option 3. One last idea a Zero-width space (&#x200B;) in between

 response.write "<a href='http://www.exa&#x200B;"
 response.write "mple.com/somepage?lang=fr'>GO</a>"

Works in the browser

0
votes

Have you tried a simple page that does nothing but what you are trying to test:

<%@ Language="javascript" %>
<%

function writeUrl(langcode, url)
{
    if(url.indexOf('?')==-1)
    {
        url = url + '?lang=' + langcode;
    }
    else
    {
        url = url + '&amp;lang=' + langcode;
    }
    Response.Write(url);
}

writeUrl("fr","not even a url");

%>

Does that output what you expect?

If yes, then throw in an absolute URL to somewhere off-server. If it's still OK, then try a URL on-server? If it goes wrong then, see if there is anything else running that could be rewriting URLs for you. Is this on IIS? And which version?

Maybe open up fiddler/firebug or something similar and look at the host headers for a clue/hint (long shot).

Does it happen always, or only if you echo the output inside a anchor tag ()?