473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a domain name of a site

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.Http Context.Current .Request.Server Variables["SERVER_NAM E"].ToLower();

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

return serverName;

}

if(serverName.E ndsWith(".com") || serverName.Ends With(".net")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".com".Leng th - 1) + 1);

}

if(serverName.E ndsWith(".co.uk ")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".co.uk".Le ngth - 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
Feb 17 '06 #1
3 1738
Look at the Request.Url class, it has a number of useful properties.

Karl
--
http://www.openmymind.net/

"Adam Tibi" <ad*******@nosp am.com> wrote in message
news:O8******** ******@TK2MSFTN GP11.phx.gbl...
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.Http Context.Current .Request.Server Variables["SERVER_NAM E"].ToLower();

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

return serverName;

}

if(serverName.E ndsWith(".com") || serverName.Ends With(".net")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".com".Leng th - 1) + 1);

}

if(serverName.E ndsWith(".co.uk ")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".co.uk".Le ngth - 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

Feb 17 '06 #2
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

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:eQ******** ******@tk2msftn gp13.phx.gbl...
Look at the Request.Url class, it has a number of useful properties.

Karl
--
http://www.openmymind.net/

"Adam Tibi" <ad*******@nosp am.com> wrote in message
news:O8******** ******@TK2MSFTN GP11.phx.gbl...
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.Http Context.Current .Request.Server Variables["SERVER_NAM E"].ToLower();

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

return serverName;

}

if(serverName.E ndsWith(".com") || serverName.Ends With(".net")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".com".Leng th - 1) + 1);

}

if(serverName.E ndsWith(".co.uk ")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".co.uk".Le ngth - 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


Feb 17 '06 #3
if (address.Starts With("www."))
{
address = address.SubStri ng(4);
}

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Adam Tibi" <ad*******@nosp am.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:eQ******** ******@tk2msftn gp13.phx.gbl...
Look at the Request.Url class, it has a number of useful properties.

Karl
--
http://www.openmymind.net/

"Adam Tibi" <ad*******@nosp am.com> wrote in message
news:O8******** ******@TK2MSFTN GP11.phx.gbl...
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.Http Context.Current .Request.Server Variables["SERVER_NAM E"].ToLower();

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

return serverName;

}

if(serverName.E ndsWith(".com") || serverName.Ends With(".net")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".com".Leng th - 1) + 1);

}

if(serverName.E ndsWith(".co.uk ")) {

return serverName.Subs tring(serverNam e.LastIndexOf(" .",
serverName.Leng th - ".co.uk".Le ngth - 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



Feb 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6801
by: Hal Vaughan | last post by:
I'm trying to access a site with data that needs to be paged through, one page at a time. It won't allow back buttons and you have to use the menu links to get through. In other words, it is run through CGI (ASP, I think) and must be able to keep track of sessions. I have a simple program I've written using Perl and LWP. I tried a totally...
1
8615
by: jach | last post by:
How can I get the domain, username and PC network name (Win 2000 Pro & Win XP Pro PC's) of the current logged on user (logged onto a domain and access an intranet page, Window 2000 server running IIS) and put this automatically in a textbox in an webpage. Can this be done with asp & VB? I basically want to automatically populate a username...
1
1780
by: news | last post by:
If there's a more appropriate group to ask this question, please let me know. I have an e-commerce site, and a few domain names I plan to use for it: name.com, name.net, name.info, name.biz, etc. When it comes to improving page ranking, what would be better? To keep each one seperate and copy the site into each domain, or have the site...
6
2815
by: Bengt Richter | last post by:
It seems lately all my posts have been coming back to me as bounced emails, and I haven't emailed them ;-( I've been getting bounce messages like (excerpt): .... _______________________________________________ This is the Postfix program at host deimos.liage.net. I'm sorry to have to inform you that your message could not be
5
1245
by: VM | last post by:
Hi, I'm interested in registering my domain name but I'm not sure which company I'll choose to host my site. Is it possible to just register my name at one company (I was thinking of www.whois.com) and then search for another company that'll host my site? My main concern is reserving the name so I have exclusive rights to it. Thanks, VM
3
4279
by: Dan Nash | last post by:
Hi Any ideas on this... having moved the web app to another server, and setup all the WebApp data (disable anonymous access etc), locally my site still asks me for a Username/Password, even though I've got authentication="Windows" in web.config. On another machine on the network, I don't get the Login box, but I just get a 401.2 error...
5
2694
by: Dany C. | last post by:
We have install a valid SSL certificate issued to www.mycompany.com on our web server running IIS 6.0 / win2003 SP1. Then we have created a sub domain pointing to the same server for our web services at ws.mycompany.com. We have properly installed the server certificate on the client machine. When the client try to connect to our secure...
12
2863
by: js | last post by:
Hi list, I have a list of URL and I want to sort that list by the domain name. Here, domain name doesn't contain subdomain, or should I say, domain's part of 'www', mail, news and en should be excluded. For example, if the list was the following ------------------------------------------------------------ http://mail.google.com
0
2864
by: sdgvfwe | last post by:
samba domain controller web hosting gratis eigene domain com domain ueberpruefen web site de + + + http://jhku.net/DOMAINS-KOSTENLOS/ http://jhku.net/DOMAINS-KOSTENLOS/ http://jhku.net/DOMAINS-KOSTENLOS/ http://jhku.net/DOMAINS-KOSTENLOS/
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7965
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7483
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6051
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.