get servername

G

Guest

I have a web app that sends an email to user and in the email it provides a
link to a detailed page on their information. My question is, when the email
is sent how can i get the web server name so when they click on the link it
takes them to the web server were the email was generated from?
 
G

Guest

I think you can use the HttpContext class to get the sort of information your
looking for.
 
J

jongalloway

1. You can use the Dns.GetHostName() to get the server's hostname:

http://msdn.microsoft.com/library/d...ml/frlrfSystemNetDnsClassGetHostNameTopic.asp

However, the hostname will probably just be a machine name (such as
WEBSERVER1). You can implement mapping logic that says which hostname
maps to which DNS.

2. If you can just use IP's, it's simpler, but a server may have
multiple IP's (such as local 127.x.x.x, internal 10.x.x.x and
external). You can get a list of IP's from a hostname:

IPHostEntry iphostentry = Dns.GetHostByName(strHostName);

// Enumerate IP addresses
int nIP = 0;
foreach(IPAddress ipaddress in iphostentry.AddressList)
{
Console.WriteLine("IP #" + ++nIP + ": " +
ipaddress.ToString());
}

See:
http://www.codeguru.com/Csharp/Csharp/cs_network/article.php/c6041/

3. You can use properties in the Request object is you're responding to
an HTTP request. You can parse the Request Server Varibles, but I'd
recommend using the Url's built in parsing features:

Request.Url.GetLeftPart(UriPartial.Authority)
Hope that gets you started.

- Jon
http://weblogs.asp.net/jgalloway
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top