开发者

Classic ASP (JavaScript) changes the URL string being echoed

I'm trying to echo out a url in my classic ASP (Ja开发者_StackOverflowvaScript) 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).


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.


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


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 ()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜