There is nothing wrong with the code,if you change it it may not work correctly.
You need to understand what host names are and how they are resolved to ip addresses by DNS or by the hosts file on your machine located at c:\Windows\System32\drivers\etc\hosts
You will see there
127.0.0.1 localhost
you can add others like:
127.0.0.1 somearbitraryhostname
This will help you testing but in production it will be based on DNS servers resolving the host names.
So if you make a web url http://localhost/ then WebUtils.GetHostName() is going to return localhost and if you make a request http:/somearbitraryhost then it will return somearbitraryhost
But VS Web server is not going to respond to 2 host names, its going to use localhost:someport
If you want to test host names you should use IIS not the VS web server.
Hope it helps,
Joe