Loading ...

How to: Get domain name from Request object in ASP.NET | CodeAsp.Net

How to: Get domain name from Request object in ASP.NET

 /5
0 (0votes)

Suppose you are running your ASP.NET application on a domain like http://www.mydomain.com, and you want to access this domain (www.mydomain.com) in your code. The below method can be used to get the host name:

 string host= HttpContext.Current.Request.Url.Host;

One problem with this is that it will not get port number. For detailed explanation and other possible solutions, refer this link for details:

http://forums.asp.net/t/1187298.aspx

Here is another solution which handles port number too.

http://stackoverflow.com/questions/689678/request-url-host-and-applicationpath-in-one-call

Comments (no comments yet)

Top Posts