Searching URL String for Subdomain value - DOTNET

This is a discussion on Searching URL String for Subdomain value - DOTNET ; I have my DNS setup to answer for any subdomain. I need to be able to look at the URL typed in like "joe.mysite.com" and put the subdomain in a variable, so I can then look it up in a ...

+ Reply to Thread
Results 1 to 3 of 3

Searching URL String for Subdomain value

  1. Default Searching URL String for Subdomain value

    I have my DNS setup to answer for any subdomain. I need to be able to
    look at the URL typed in like "joe.mysite.com" and put the subdomain
    in a variable, so I can then look it up in a database. This would have
    to work if they typed in http://joe.mysite.com or just joe.mysite.com.

    Here is what I have started with, but as you can see I'm a little
    stuck.

    Sub ExtractDomain(ByVal expr As String)

    Dim sURL As String = Page.Request.Url.ToString()
    Dim subDomain = InStr(1, sURL, "http://")
    If subDomain > 0 Then
    'True so count over 7 characters


    Else
    'False, so start immediately


    End If

    End Sub


  2. Default Re: Searching URL String for Subdomain value

    hi,
    you should use regular expressions for this job, they are in their element
    here.
    you can use the expression [\w-]+ to match all the components of a URL.
    for example, running Regex.Matches on http://joe.mysite.com will yield 4
    captures in the first group:
    http joe mysite com
    you can then decide how you want to deal with them. you want to support
    someone using HTTPS, and also a domain without a subdomain, such as
    http://mysite.com or even http://mysite if running in an intranet
    environment.
    plenty of regex tutorials on the net and in the SDK docs if you need a
    refresher on regex.
    good luck
    tim

    "CSINVA" <mcse_instructor@yahoo.com> wrote in message
    news:1193880562.557651.135010@v3g2000hsg.googlegroups.com...
    >I have my DNS setup to answer for any subdomain. I need to be able to
    > look at the URL typed in like "joe.mysite.com" and put the subdomain
    > in a variable, so I can then look it up in a database. This would have
    > to work if they typed in http://joe.mysite.com or just joe.mysite.com.
    >
    > Here is what I have started with, but as you can see I'm a little
    > stuck.
    >
    > Sub ExtractDomain(ByVal expr As String)
    >
    > Dim sURL As String = Page.Request.Url.ToString()
    > Dim subDomain = InStr(1, sURL, "http://")
    > If subDomain > 0 Then
    > 'True so count over 7 characters
    >
    >
    > Else
    > 'False, so start immediately
    >
    >
    > End If
    >
    > End Sub
    >



  3. Default Re: Searching URL String for Subdomain value


    "CSINVA" <mcse_instructor@yahoo.com> wrote in message
    news:1193880562.557651.135010@v3g2000hsg.googlegroups.com...
    >I have my DNS setup to answer for any subdomain. I need to be able to
    > look at the URL typed in like "joe.mysite.com" and put the subdomain
    > in a variable, so I can then look it up in a database. This would have
    > to work if they typed in http://joe.mysite.com or just joe.mysite.com.
    >


    Use System.Uri and the TryCreate method, then check the Host property.



+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 10-24-2007, 10:06 AM
  2. searching an array, string compare functions, string sorting
    By Application Development in forum Javascript
    Replies: 2
    Last Post: 10-10-2007, 06:23 PM
  3. searching for a special string in an array
    By Application Development in forum Perl
    Replies: 4
    Last Post: 07-16-2007, 08:40 AM
  4. String Searching in SQL?
    By Application Development in forum JDBC JAVA
    Replies: 5
    Last Post: 07-07-2007, 09:25 AM
  5. Help with searching a file for a string
    By Application Development in forum c++
    Replies: 8
    Last Post: 11-08-2006, 05:17 PM