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 / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Getting a domain name of a site

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Adam Tibi - 17 Feb 2006 12:07 GMT
Hi,

Is there a way of getting the domain name of tghe currently executing site,
I tried using this silly code:

public static string GetDomainName() {

string serverName =
System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();

if(!serverName.Contains(".")) {

   return serverName;

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net")) {

   return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length - ".com".Length - 1) + 1);

}

if(serverName.EndsWith(".co.uk")) {

   return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length - ".co.uk".Length - 1) + 1);

}

   return null;

}

But I don't think that this is the right solution, does any one have a NEAT
solution for this, for example by using the URI class or some thing?

Adam Tibi
Karl Seguin [MVP] - 17 Feb 2006 12:12 GMT
Look at the Request.Url class, it has a number of useful properties.

Karl
Signature

http://www.openmymind.net/

> Hi,
>
[quoted text clipped - 34 lines]
>
> Adam Tibi
Adam Tibi - 17 Feb 2006 14:22 GMT
Thank You Karl, actually, I am interested in getting the last portion of the
domain only, so if my site is www.xyz.co.uk then I need to get xyz.co.uk and
if my site is abc.xyz.com then I am only interested in the xyz.com part.

I still need to go through the logic of the method I provided below!

Ideas?
Regards,
Adam Tibi

> Look at the Request.Url class, it has a number of useful properties.
>
[quoted text clipped - 37 lines]
>>
>> Adam Tibi
Karl Seguin [MVP] - 17 Feb 2006 15:13 GMT
if (address.StartsWith("www."))
{
  address = address.SubString(4);
}

Karl
Signature

http://www.openmymind.net/
http://www.fuelindustries.com/

> Thank You Karl, actually, I am interested in getting the last portion of
> the domain only, so if my site is www.xyz.co.uk then I need to get
[quoted text clipped - 49 lines]
>>>
>>> Adam Tibi

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



©2009 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.