473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

determining the web domain name

Hi

I need to be able to determine the domain name the web page has been called
from. I have a site that can be accessed through different domain names
(they all point to the same IP address) eg. www.abc.com and www.bcd.com

Is there a way to do this in the ASPX code in C#

Many thanks

Jonny

P.S I did post this message before but it didn't show up in my news reader.
Nov 18 '05 #1
3 1062
string[] url = Request.Url.ToString().Replace(@"http://",
String.Empty).Split('/');

Then examine url[0].

string currentDomain = url[0];

You can even do logic like:

switch(currentDomain)
{
case "www.mysite1.com":
//do some work here
break;
default:
//main site, catch all
//Do work here
break;
}

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Jonny Wilkinson" wrote:
Hi

I need to be able to determine the domain name the web page has been called
from. I have a site that can be accessed through different domain names
(they all point to the same IP address) eg. www.abc.com and www.bcd.com

Is there a way to do this in the ASPX code in C#

Many thanks

Jonny

P.S I did post this message before but it didn't show up in my news reader.

Nov 18 '05 #2
Now that I think for a minute (getting so used to parsing), the System.Uri
object makes things even simpler. Try:

System.Uri url = Request.Url;
string hostname = url.Host.ToString();

In VB.NET:

Dim url As System.Uri = Request.Url
Dim hostname As String = url.Host.ToString()
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Jonny Wilkinson" wrote:
Hi

I need to be able to determine the domain name the web page has been called
from. I have a site that can be accessed through different domain names
(they all point to the same IP address) eg. www.abc.com and www.bcd.com

Is there a way to do this in the ASPX code in C#

Many thanks

Jonny

P.S I did post this message before but it didn't show up in my news reader.

Nov 18 '05 #3
Fantastic - thanks Gregory!

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:F0**********************************@microsof t.com...
Now that I think for a minute (getting so used to parsing), the System.Uri
object makes things even simpler. Try:

System.Uri url = Request.Url;
string hostname = url.Host.ToString();

In VB.NET:

Dim url As System.Uri = Request.Url
Dim hostname As String = url.Host.ToString()
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Jonny Wilkinson" wrote:
Hi

I need to be able to determine the domain name the web page has been
called
from. I have a site that can be accessed through different domain names
(they all point to the same IP address) eg. www.abc.com and www.bcd.com

Is there a way to do this in the ASPX code in C#

Many thanks

Jonny

P.S I did post this message before but it didn't show up in my news
reader.

Nov 18 '05 #4

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

Similar topics

9
by: Christopher Benson-Manica | last post by:
I have the following situation: Page A opens a window named 'foo'. Page A then reloads itself. Is there a way for the reloaded Page A to determine whether there is an open window named 'foo',...
2
by: JZ | last post by:
Hi, At run-time, I need to determine the domain on which the server is currently joined. System.Environment doesn't provide me with the information that I need through the UserDomainName...
2
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
2
by: Richard L Rosenheim | last post by:
On my development machine, it works -- SystemInformation.UserDomainName and System.Environment.UserDomainName both returns the domain name. But, on my test machine, these methods are returning the...
1
by: chad.poplawski | last post by:
Hi All, I'm working on a Windows Service that uses FileSystemWatcher components to capture and log data when certain actions (such as files being deleted) take place in the file system. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.