Allow remote access to IISExpress for development in VS

When you want to test your website and check it remote you see the error:

Bad Request – Invalid Hostname


HTTP Error 400. The request hostname is invalid.

First thing to do is to find the correct applicationhost.config file. This file can be found in

the solution directory under .vs/<Solution name>/config. This file contains an entry under the tag <sites> for the site with the config that is applied in IISExpress.

This enables binding for the IIS:

    <bindings>
      <binding protocol="http" bindingInformation="*:29136:localhost" />
      <binding protocol="https" bindingInformation="*:44343:localhost" />
    </bindings>

Above configuration only allows localhost to access the IISSExpress site.

Change it to:
        <bindings>
          <binding protocol="http" bindingInformation=":29136:" />
          <binding protocol="https" bindingInformation=":44343:" />
        </bindings>
to allow remote machines to access the site.

Debugging Windows Service in Visual Studio

After some searching and testing how to debug a windows service, I found that for me the following solution is working very well.

First register your service as a service on your machine. This can be done with a few simple steps. How to do this is described in this article: http://kannekens.nl/registering-installing-a-windows-service/

Next add a line / lines Debugger.Break(); in your code where you want the debugger to start. Now compile in debug mode clicking in Visual Studio menu: Build, Build Solution while the Configuration Manager is set to Debug.

After the application compiled successfully we can stop and start the service to ensure these modifications are run:

I used the tips from https://docs.microsoft.com/en-us/dotnet/framework/windows-services/how-to-debug-windows-service-applications and https://stackoverflow.com/questions/104235/how-can-i-use-debugbreak-in-c.

Right click the Visual Studio application and select more…, Run as administrator

Click Debug, Attach to Process in the Visual Studio menu.

This will open a dialog where you need to select the right process to debug. Check the Show processes from all users checkbox. Find your Service process and click Attach.