Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2007

Tip: Looking for answers? Try searching our database.

Searching URL String for Subdomain value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CSINVA - 01 Nov 2007 02:29 GMT
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
Tim Mackey - 12 Nov 2007 10:39 GMT
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

>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
[quoted text clipped - 17 lines]
>
>    End Sub
Ben Voigt [C++ MVP] - 12 Nov 2007 16:34 GMT
>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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.