?
Solved

Strip Part Of An Address To Form A Query String

Posted on 2005-04-18
18
Medium Priority
?
288 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:net-workx
  • 11
  • 7
18 Comments
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811363
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
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811465
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
 

Author Comment

by:net-workx
ID: 13811513
Have just pasted that code onto a blank default page of the server and it displays The Page Cannot Be Found?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811620
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
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811641
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
 

Author Comment

by:net-workx
ID: 13811671
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
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811695
Im getting

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

which would be correct...

Hmmmm

0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811702
Comment this out:

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

0
 

Author Comment

by:net-workx
ID: 13811757
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
 

Author Comment

by:net-workx
ID: 13811809
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
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811814
That's good because I'm having intermittent ISP connection issues.

I'll be around tommorow
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13811872
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
 

Author Comment

by:net-workx
ID: 13813981
Anyone else care to offer any suggestions?
0
 

Author Comment

by:net-workx
ID: 13814556
As is seems more and more impossible im increasing the points,

Thanks,
Carl
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13815170
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
 

Author Comment

by:net-workx
ID: 13815460
Pretty sure that would work looking at it, however!!!!  I cant change the error pages on the 1and1 package!
0
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 1500 total points
ID: 13816303
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
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 25949036
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question