• How to get HOST Name from HttpRequest

    Posted on May 31, 2012 by in Dotnet Tips & Tricks, Tips & Tricks

    public static string GetHostName(System.Web.HttpRequest httprequest)
            {
                string hostname = String.Empty;
                try
                {
                    if (httprequest != null)
                    {
                        if (httprequest.Url != null)
                        {
                            hostname = httprequest.Url.Host;
                        }
                    }
                }
                catch
                {
                    hostname = Environment.MachineName;
                }
                return hostname;
            }
    Be Sociable, Share!
      Post Tagged with

    Written by

    View all articles by

    Email : [email protected]

    Leave a Reply