We help IT Professionals succeed at work.

ASP Classic, check if Querystring is UCase or LCase

Wayne Barron
Wayne Barron asked
on
278 Views
Last Modified: 2017-05-14
Hello All;

I designed a lot of my sites with a certain case sensitive structure.
Of which in the most part, has never been an issue.
But there is always the time when someone might type out the URL to a location on the site.
And they do lowercase instead of Uppercase.

What I would like to be able to accomplish, is to check if the string is all lowercase and if it is.
Check the URL and do a redirect.
Well, without doing an endless LOOP. (That is what I am afraid of)

So, how would you check?
main.asp?type=something
And then have it changed to
main.asp?Type=Something

Any ideas on this one?
(And yes, I know. I have read where it is bad programming to do it like I have, but this was done such a long time ago.
And there is well over 100+ pages per site, that I would have to change. Not quite ready to do that yet.)
Thanks, all.
Carrzkiss
Comment
Watch Question

CERTIFIED EXPERT

Commented:
for asp websites, it really doesn't matter if you give the parameters as uppercase or lowercase.

this is a simple test:

<%

    response.write("request(""type"") = " & request("type") & "<br>")
    response.write("request(""Type"") = " & request("Type") & "<br>")
    response.write("request(""TYpE"") = " & request("TYpE") & "<br>")
    response.write("request(""tyPE"") = " & request("tyPE") & "<br>")

%>

Open in new window


but certainly, for values, it do make difference.
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:
It is the values.
I should have made that clear. Sorry.
CERTIFIED EXPERT

Commented:
you probably can test using some codes like this:

<%

response.write("Test 1 = " & getOutput("dfij23ed") & "<br>")
response.write("Test 2 = " & getOutput("H %j23ed") & "<br>")
response.write("Test 3 = " & getOutput("df%d") & "<br>")
response.write("Test 4 = " & getOutput("323x") & "<br>")
response.write("Test 5 = " & getOutput("dfijz23ed") & "<br>")
response.write("Test 6 = " & getOutput("633") & "<br>")
response.write("Test 7 = " & getOutput("!@#$%Fd") & "<br>")
response.write("Test 8 = " & getOutput("HHYx") & "<br>")
response.write("Test 9 = " & getOutput("df632ed") & "<br>")
response.write("Test 10 = " & getOutput("ABC") & "<br>")

function getOutput(value)
    rtn = isAllLowerCase(value)
    if rtn then
        getOutput = value & " is " & rtn
    else
        getOutput = "<font color='red'>" & value & " is " & rtn & "</font>"
    end if
end function

function isAllLowerCase(value)
    for i = 1 to len(value)
        v = mid(value, i, 1)
        if asc(v) >= 65 and asc(v) <= 90 then
            isAllLowerCase = false
            exit function
        end if
    next
    isAllLowerCase = true
end function

%>

Open in new window


to apply to your verification, use isAllLowerCase(value) and replace the value with querystring.
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:
How would I use it to test against the Querystring?

Type=something
that supposed to be
Type=Something
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:
Hey, Ryan.

I test it out, and it works like a charm.
I am assuming that I would add the Redirect to here.

[code]    isAllLowerCase = true
      response.Redirect "?Type=Something"
end function[/code]
As this is what I did, and the test works pretty good.
I type in the following URL: Type=something
And it reloads the page to: Type=Something

Love it.
Thank you, very much.
Now, I have to implement it into the test site.
It is going to be a week before this site is ready to be sent live to update the existing site.
So, I will have all that time to test it out to make sure that everything is going to work right.

You rock my friend.
Have a rockin rest of the week.
Wayne
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:
I am doing this with it, and it is working great.

    isAllLowerCase = true
	if request.QueryString("Type")="artlist" then
	response.Redirect "?Type=ArtList"
	end if
end function

Open in new window

This way I can control what gets checked and redirected.

Please, let me know if this would cause an issue.
Wayne
CERTIFIED EXPERT

Commented:
let me know if this would cause an issue.

    isAllLowerCase = true
	if request.QueryString("Type")="artlist" then
	response.Redirect "?Type=ArtList"
	end if
end function

Open in new window


yup this should work well. but you may consider few issues:

1. reusability - can this code be reuse in some where else in your asp web pages?
2. configurability - how easy and frequent if we want to edit the values?
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:
Hey, Ryan.
This code would wonderfully.
I have it setup to capture all pages and no issue.

I do have one slight thing, though.

Every page you see:
info is True
Thread is True
Forum is True, etc...

How can I either, HIDE or get rid of this?
Having it showing all the time is not a good thing.
Though on the regular site, it is hidden behind the HEADER.
But that is not the case for mobile. It is shown right under the Menu, on every page.

Any idea's on this would be wonderful.
Wayne
CERTIFIED EXPERT

Commented:
Every page you see:
info is True
Thread is True
Forum is True, etc...

what do you mean by that?

are that "info", "Thread", and "Forum" the variables?