-2

I am using basic ASP and I want to display one of two images depending on the URL of the page. Here's my best shot at it:

<%
  Dim myURL
  myURL = "https://www.domainname.com:443/Index.asp"
  If myURL = "<% response.write(curPageURL()) %>" Then
       response.write("<img src="img/image1-logo-150x50.png" width="150" height="50" alt="sitename">")
  Else
       response.write("<img src="img/image2-logo-80x80.jpg" width="80" height="80" alt="sitename">")
  End If
%>

I'm stuck, and can only get a Server Error 500 response for my efforts. Any insights would be greatly appreciated. BTW, I tested <% response.write(curPageURL()) %> and it does retrieve the page URL in the format shown in my code.

Based on GSerg's link I changed my code to this, but it still doesn't work:

<%
  Dim myURL
  myURL = "https://www.domainname.com:443/Index.asp"
  If myURL = "<% response.write(curPageURL()) %>" Then
       response.write("<img src=""img/image1-logo-150x50.png"" width=""150"" height=""50"" alt=""sitename"">")
  Else
       response.write("<img src=""img/image2-logo-80x80.jpg"" width=""80"" height=""80"" alt=""sitename"">")
  End If
%>

Perhaps I misunderstood.

I have corrected the error using response.write, and the server now runs the code; however, the condition is not working. I did a write test on the page URL to get the format that curPageURL() returns, but when I'm on the page that should display image1, it only displays image2. Here's what I'm using:

  <%
  Dim myURL
  myURL = "curPageURL()"
  If myURL = "https://www.domainname.com:443/Index.asp" Then
       response.write("<img src=""img/image1-logo-150x50.png"" width=""150"" height=""50"" alt=""name"">")
  Else
       response.write("<img src=""img/image2-logo-80x80.jpg"" width=""80"" height=""80"" alt=""name"">")
  End If
  %>
  • 2
    Does this answer your question? [About using Double quotes in Vbscript](https://stackoverflow.com/questions/15770599/about-using-double-quotes-in-vbscript) – GSerg Jun 03 '21 at 16:18
  • My takeaway from the link was that I had to add a second set of double quotes around each internal set of double-quotes. I tried that and it didn't work. – Warren Rosenfeld Jun 03 '21 at 16:28
  • The `If myURL = "<% response.write(curPageURL()) %>" Then` doesn't make sense. Did you mean `If myURL = curPageURL() Then`? – GSerg Jun 03 '21 at 16:36
  • What @GSerg says is absolutely true and you didn’t misunderstand but you also have the problem of `If myURL = "<% response.write(curPageURL()) %>" Then` which will never work. You can’t use `Response.Write()` in an `If` statement like that, it will never work. Instead you need to compare the `myURL` string variable with what I assume is a string containing the current page `curPageURL`. – user692942 Jun 03 '21 at 16:37
  • Yes GSerg, thankyou. I should have used If myURL = curPageURL() Then – Warren Rosenfeld Jun 03 '21 at 16:42

1 Answers1

0

This:

<%
    Dim myURL
    myURL = "curPageURL()" ' <-- Here's your problem
  
    ' [...]
%>

Should be like this below:

<%
    Dim myURL
    myURL = curPageURL()

    Const testUri = "https://www.domainname.com:443/Index.asp"

    If StrComp( myURL, testUri, vbTextCompare ) = 0 Then
        Response.Write "<img src=""img/image1-logo-150x50.png"" width=""150"" height=""50"" alt=""name"" />"
    Else
        Response.Write "<img src=""img/image2-logo-80x80.jpg"" width=""80"" height=""80"" alt=""name"" />"
    End If
%>
Dai
  • 141,631
  • 28
  • 261
  • 374
  • @WarrenRosenfeld Out of curiosity, why are you using Classic ASP in 2021? It's been obsolete for 20 (yes, _twenty_) years now... – Dai Jun 03 '21 at 17:30
  • I haven't done any programming in about 20 years, so it was easier to start refreshing myself on this rather than learn the modern languages. Besides, my needs are simple and this still works. – Warren Rosenfeld Jun 03 '21 at 17:36
  • 1
    Welcome to StackOverflow. If a contributor solves your problem - mark the answer as accepted :) @Dai - Classic ASP isn't obsolete as long as current versions of IIS support it, which they do. There's still a surprising amount of it out there. Developers will often build on existing code rather than throw everything away and start again. And some developers like it. There's actually a modern framework written in Classic ASP - https://asplite.com/ – John Jun 05 '21 at 06:42
  • 1
    @John the guy talks about using Access databases and how w3schools is a good resource, sorry can’t take him seriously. – user692942 Jun 06 '21 at 20:59
  • @user692942 w3schools has been a most reliable and uncluttered resource for many years... and it still is! However the use of Access databases online today is not only most insecure but dead slow. – WilliamK Nov 14 '21 at 06:48
  • 1
    @WilliamK I disagree. I checked W3Schools.com just now and while I agree that visually the site is less cluttered (I didn't even know I had AdBlock disabled!) there is still plenty of horrible advice being offered, for example [this page on PHP](https://www.w3schools.com/php/php_forms.asp) renders unsanitized user input directly using `` instead of doing it _safely_ with `= htmlentities( $_POST["name"] ) ?>` - the page does have a bright yellow warning message but it's about data validation, not rendering user-provided data safely: it doesn't mention XSS at all. – Dai Nov 14 '21 at 06:59
  • @WilliamK What makes Access "insecure" in your opinion? Or even "dead slow"? In decades past I've run plenty of quick-and-dirty websites off a local Access MDB where installing SQL Server (_then_ known as MSDE) was overkill (this was before Sqlite was viable). The JET driver handles concurrency, even cross-process concurrency, fine through good ol' fashioned Win32 locked-file-regions. – Dai Nov 14 '21 at 07:02
  • @Dai experience. As for w3Schools I am looking for quick coding referencse several times a day (no-one needs to remember everything) and while Google presents more alternatives today than what it should, I find that w3Schools has been the most reliable and easiest to explain. But not always as you may claim in some instances. – WilliamK Nov 14 '21 at 07:13