How to get full host name + port number in Application_Start of Global.aspx?

When your web application starts, there is no HTTP request being handled. You may want to handle define the Application_BeginRequest(Object Sender, EventArgs e) method in which the the Request context is available. Edit: Here is a code sample inspired by the Mike Volodarsky’s blog that Michael Shimmins linked to: void Application_BeginRequest(Object source, EventArgs e) { … Read more

Alias hostname for localhost

When the browser sees http://localwebapp/ it first tries to determine the IP address of localwebapp. If this succeeds, the browser establishes a TCP connection with that host, using a specific port (which is 80 for HTTP, unless some other port is mentioned in the URL). Resolving localwebapp to an IP address does not take port … Read more

How to store the hostname in a variable in a .bat file?

hmm – something like this? set host=%COMPUTERNAME% echo %host% EDIT: expanding on jitter’s answer and using a technique in an answer to this question to set an environment variable with the result of running a command line app: @echo off hostname.exe > __t.tmp set /p host=<__t.tmp del __t.tmp echo %host% In either case, ‘host’ is … Read more

Difference between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName

Environment.MachineName and System.Windows.Forms.SystemInformation.ComputerName are identical and returns the computer’s NetBIOS name. This name is restricted to 15 characters and only visible on the LAN. System.Net.Dns.GetHostName() returns the computer’s TCP/IP based hostname. By adding a domain suffix to the hostname you can resolve your computer’s IP address across LANs / on the internet. System.Environment.GetEnvironmentVariable(“COMPUTERNAME”) returns the … Read more