How to get current domain name in ASP.NET

20+ years of Proud Existence in Web, Intranet, Mobile App development in India


Problem?
How to get current domain name in ASP.NET? 


Solution:
Public Shared Function GetCurrentDomainName() As String
Dim domain As String


domain = HttpContext.Current.Request.ServerVariables(‘SERVER_NAME’)
domain = domain.Replace(‘www.’, ”)


Return (domain)
End Function