determining the web domain name

J

Jonny Wilkinson

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.
 
G

Guest

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!
***************************
 
G

Guest

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!
***************************
 
J

Jonny Wilkinson

Fantastic - thanks Gregory!



Cowboy (Gregory A. Beamer) - MVP said:
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!
***************************
 
Joined
Dec 26, 2008
Messages
1
Reaction score
0
Tried Code - Have Problems

I tried this code and on my local server it works fine but on the production server it returns an empty string.

Could this be some type of permissions issue? Anyone else experience problems retrieving Server Variables on a production ASP.NET server?

Thanks,
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top