Hackviking He killed Chuck Norris, he ruled dancing so he took up a new hobby…

9Jan/150

Webmatrix 3: Access dev site from other device

Webmatrix 3 Loggo

Webmatrix 3 is a free tool by Microsoft for web development. It supports a range of languages, frameworks and CMS like WordPress for instance. It automates the process of installing frameworks, compilers and database backends. It will quickly setup a development environment on your computer so you can start develop. Lately I have been using it to create a new responsive theme for this website. It works out of the box for testing on localhost but not everybody is running 1080p monitors and I need to test on my phone, tablet and laptop as well. Out of the box it doesn't support this but here is how you set it up.

Webmatrix relies on IIS express in the background and is therefor fully configurable like it was a normal IIS server. When I was testing this out I got the server to bind to any and all IP addresses the machine had but when I restarted Webmatrix it just crashes. To navigate around this I recommend that you use a static IP on your machine or make your DHCP server always assign you the same one. This also makes WordPress development easier since you have to configure a siteurl and a home for the site. On the development environment this is usually http://yourip:someport so if your machine changes IP address all the time you will have to update this each time you start your development.

If you have made a standard install of Webmatrix then your config file is located at: C:\Users\{username}\Documents\IISExpress\config\applicationhost.config

This is a standard XML IIS config file. Look for the <sites> section in your file. There will be a <site> entry for each of your development sites. In this example for my local dev copy of hackviking.com

<site name="Hackviking Dev" id="2128771976">
     <application path="/" applicationPool="UnmanagedClassicAppPool">
         <virtualDirectory path="/" physicalPath="C:\Users\Källsbo\Documents\My Web Sites\Hackviking Dev" />
     </application>
     <bindings>
         <binding protocol="http" bindingInformation="*:17063:localhost" />
     </bindings>
</site>

The interesting part here is the "bindingInformation" part. It consists of three parts {ip address to bind}:{port to bind}:{host header}. So as we can see it binds to localhost at the moment. So if I try to access this site from an other machine the IIS will not bind the host header, in this case the IP address typed in to the address bar. So if we replace it with this instead:

<site name="Hackviking Dev" id="2128771976">
    <application path="/" applicationPool="UnmanagedClassicAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\Källsbo\Documents\My Web Sites\Hackviking Dev" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:17063:192.168.0.30" />
    </bindings>
</site>

So now the host header will bind to the IP address and external access is possible on the local network. You could even do a port forward and run this publicly but I wouldn't recommend it performance wise. For this to work you will have to right click Webmatrix and select "Run as administrator" otherwise the bind will fail and IIS will not start!

Comments (0) Trackbacks (0)

No comments yet.


Leave a Reply

No trackbacks yet.