1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Retrieving url properties

Discussion in 'C#' started by red_fiesta, Oct 26, 2006.

  1. #1
    Is there a way in asp to retrieve part of the URL and use it

    say the url was

    http://localhost/site/craig

    is there anyway of retrieving the word craig so to use it in the page

    This is because i could have other addresses that are for example

    http://localhost/site/Jon

    where i need to retrieve the word jon
     
    red_fiesta, Oct 26, 2006 IP
  2. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #2
    Here is some code to do it.


    Lets say the current page is simply "http://www.mysite.com/view_user.asp"

    This is all you need to get you the current page URL
    <%
    Thispage = Request.ServerVariables("script_name")
    %>

    Now, if your page has Querystring info and variables you want as well.
    Like so "http://www.mysite.com/view_user.asp?ID=1&Name=Fred"

    you would use code like this.

    <%
    Thispage = Request.ServerVariables("script_name") & "?" & Request.Querystring
    %>
     
    ludwig, Oct 26, 2006 IP
  3. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3


    so i that returned /files/craig/Default.asp how could i just put the name craig into a string baring in mind the /files/ is always going to be there and the file will always be called default.asp

    ie i could have directories /files/jon/Default.asp where i need jon to be returned...
     
    red_fiesta, Oct 26, 2006 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    here is a sample where I keep the domain name only from the refering site
    maybe you can figure out :) I don't want to post the script for you, I want to help you achieve it :)
     
    ludwig, Oct 26, 2006 IP
  5. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <%
    Function ParseDomainFromURL(url)
    urlParts = split(url,"/")
    ParseDomainFromURL = urlParts(2)
    End Function
    domain = parseDomainFromURL("http://www.mobile.am/?lang=en")
    %>

    I wanna work it out as well...

    i guess i need to pass something to the function url

    what i dont understand is why i need this.. domain=

    surely that should be calling the function.. and where is the output?
     
    red_fiesta, Oct 26, 2006 IP
  6. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <%
    Function ParseDomainFromURL(url)
    urlParts = split(url,"/")
    ParseDomainFromURL = urlParts(2)
    End Function
    url = parseDomainFromURL(Request.ServerVariables("URL"))
    Response.Write(url)
    %>

    would be my guess
     
    red_fiesta, Oct 26, 2006 IP
  7. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    or could do

    <%

    sMyString = Request.ServerVariables("URL")
    sMyString = Replace(sMyString, "/", "")
    sMyString = Replace(sMyString, "files", "")
    sMyString = Replace(sMyString, "default.asp", "")
    sMyString = Replace(sMyString, "Default.asp", "")


    Response.Write sMyString

    %>

    Which one is better?
     
    red_fiesta, Oct 26, 2006 IP
  8. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #8
    try this

    or

     
    ludwig, Oct 26, 2006 IP