Strip Part Of An Address To Form A Query String

Hi,

I would like to know how to take the address from the browers and strip all after the first / and use that in a query string?

IE......

www.mysite.com/AB101

UserID = Strip.Address.FirstSlash

IF NOT IsNull(UserID) THEN
     Response.Redirect "/property.asp?PageID=home&UserID=<% Response.Write UserID %>"
END IF

The Resulting link would be...

www.mysite.com/property.asp?PageID=home&UserID=AB101

Any Ideas?

Thanks,
Carl
net-workxAsked:
Who is Participating?
 
rdivilbissCommented:
That would be a bit of a bummer....

They are separate for each domain.  Once you have the page the way you want it, can you ask their technicians to change it for you?  It is a very simple task, and I doubt there would be any significant charge.

You can always coax them with discountasp.net allows you to change the 404 and 500 pages for free (which they do, by the way.)

Regards,
Rod
0
 
rdivilbissCommented:
Dim url, userid
url = request.servervariable("SCRIPT_NAME")
userid = Mid(url, InStr(usr,"/")+1)
if userid <> "" then
    url = Left(url,InStr(usr,"/")-1) & "property.asp?PageID=home&UserID=" & userid
    response.redirect url
end if

0
 
rdivilbissCommented:
Ignore post one.

I failed to consider a couple of things.

Not the least of which is www.mysite.com/AB101 is probably going to be returned as /AB101/default.asp in the server variables, and we need to capture the server name as it is not returned in the script name.


Dim url, userid, server, redir

url = request.servervariables("SCRIPT_NAME")  ' like: /AB101/default.asp
server = request.servervariables("SERVER_NAME")  ' like: www.mysite.com

if InStr(2, url, "/") > 0 then   ' find the second / and get rid of the page name or anything else following
      userid = Mid(url, 1, InStr(2, url, "/")-1)
else
      userid = Mid(url, 1)  ' should never be executed
end if      

if userid <> "" then
    redir = "http://" & server & url & "property.asp?PageID=home&UserID=" & Mid(userid,2)
    response.redirect redir
    ' response.write redir
end if

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
net-workxAuthor Commented:
Have just pasted that code onto a blank default page of the server and it displays The Page Cannot Be Found?
0
 
rdivilbissCommented:
That's because the page created in the example does not exist...

comment out the response.redirect and uncomment the response.write.

If after your tests, you have a problem with the redirect, change it to

response.redirect(redir)

Regards,
Rod

0
 
rdivilbissCommented:
However, this line is wrong, <smile>

redir = "http://" & server & url & "property.asp?PageID=home&UserID=" & Mid(userid,2)

Putting url in there puts us right back where we started.  Just one brain fart after another over here.

redir = "http://" & server & "/property.asp?PageID=home&UserID=" & Mid(userid,2)
0
 
net-workxAuthor Commented:
Your getting closed tho i think as the Response.Write line produces this...

http://mysite.zapto.org/property.asp?PageID=home&UserID=Default.asp

just that last default.asp that needs to be the propertyID!

No matter how many brain farts you have, i wouldnt have got passed the first line to start this off!!!
0
 
rdivilbissCommented:
Im getting

http://www.rodsdot.com/property.asp?PageID=home&UserID=ee

which would be correct...

Hmmmm

0
 
rdivilbissCommented:
Comment this out:

'else
'     userid = Mid(url, 1)  ' should never be executed

0
 
net-workxAuthor Commented:
Ok here makes it even more complex...

When i just type in:

http://servername

it came up with:http://mysite.zapto.org/property.asp?PageID=home&UserID=Default.asp

When i refeshed the page again it went blank and now will not Response.Write anything

Next up, when i go:
http://servername/39

it comes up with page cannot be displayed?

0
 
net-workxAuthor Commented:
it 2:15 in the morning here so im off to bed now, will try out any more suggestions when i get up in the morning!!  Thanks for all your help!

Carl
0
 
rdivilbissCommented:
That's good because I'm having intermittent ISP connection issues.

I'll be around tommorow
0
 
rdivilbissCommented:
I'm pretty confident the latest version is fundamentally correct, however your last post points out a weakness in your original question (train of thought).

Given http://www.domain.com/AB210 and http://www.domain.com/AB211, you would have to have a default.asp in both of those folders with this code to redirect as you wish to do.

e.g. the problem is, for every user id you have you will need a corresponding folder and a default.asp page with this code.

That may be more work than you bargained for.

Rod
0
 
net-workxAuthor Commented:
Anyone else care to offer any suggestions?
0
 
net-workxAuthor Commented:
As is seems more and more impossible im increasing the points,

Thanks,
Carl
0
 
rdivilbissCommented:
You can replace the error page, Page Not Found - 404 with your own custom page containing this code.

http://www.15seconds.com/issue/980210.htm

Regards,
Rod
0
 
net-workxAuthor Commented:
Pretty sure that would work looking at it, however!!!!  I cant change the error pages on the 1and1 package!
0
 
rdivilbissCommented:
The off-site page referred to at: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Q_21393484.html#13811695 has been removed.

It is below if it is somehow still pertinent:


<%
Dim url, userid, server, redir 
url = request.servervariables("SCRIPT_NAME")  ' like: /AB101/default.asp
server = request.servervariables("SERVER_NAME")  ' like: www.mysite.com 
if InStr(2, url, "/") > 0 then   ' find the second / and get rid of the page name or anything else following
     userid = Mid(url, 1, InStr(2, url, "/")-1)
else
     userid = "" ' There is nothing but a page name after the "/"
end if      
if userid <> "" then
    redir = "http://" & server & "/property.asp?PageID=home&UserID=" & Mid(userid,2)
    'response.redirect redir
    Response.Write redir
    ' Response.Write server
end if
%>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.