Hey! Thanks for visiting. I hope you found what you're looking for here. While I do occasionally respond to comments left here, I've not actively maintaining this blog anymore. My new Internet home is http://joshuaearl.com. Why don't you check it out?
I'm getting my MacBook Air set up for some ASP.NET MVC3 development, using Parallels Desktop to run the Windows 8 release preview as a virtual machine. Even with the stingy 1GB of RAM I allotted for the VM, Windows 8 screams and Visual Studio 2010 runs great.
For this particular project, the team I'm working with is using IIS Express 7.5. It was a logical choice because it generally requires less configuration and fiddling than the full version of IIS, which tends to throw a hissy if you don't get all the directory permissions just so.
Setting up the site in my VM was no trouble at all. But then I decided to make my own life difficult: I just had to be able to view the site in my Mac's installation of Chrome so that I could use OSX Lion's amazing multitouch gestures to switch between Visual Studio and the browser. I do this all the time when working in Vim and Sublime Text, and it's a smooth and natural workflow.
So, to recap, I needed to develop my site in a Windows 8 VM running in Parallels, and I wanted to be able to serve the site up through IIS Express to my native Mac browser.
This simple scenario morphed into a bit of a multi-headed Hydra, and it took me a while to work through each step. Here's an overview of what I did to get it working.
Network and Firewall
The first step is enabling bridged networking in Parallels. This allows your virtual machine to have its own IP address, and makes it visible on your network just like any other machine.
To enable bridged networking:
- Click Main Menu | Virtual Machine | Configure.
- Click the Hardware icon.
- Select the appropriate network option from the left navigation. This might take some trial and error. Mine is called Network1.
- Select the Default Adapter option under Type. Again, you might need to experiment here. I had several adapters listed, but the default one worked.
The next step is poking a hole through the Windows Firewall to allow traffic through. I added rules for port 80 and port 8080. Here's a brief walkthrough on how to add firewall rules. You'll want both inbound and outbound rules.
Once I enabled bridged networking and created the firewall rules, I was able to hit a quick test
site I set up with IIS 8 on port 80, using the virtual machine's host name, like this:
http://my-virtual-machine-name. (To find out the host name of your virtual machine, open cmd or
PowerShell and run
IIS Express Configuration
However, when I fired up my IIS Express site and tried to access it from outside the VM, I received the following nondescript error:
400 Hostname is Invalid
Eventually I learned that this error is caused by missing bindings in the IIS Express configuration
file. My site was bound to
*:8080:localhost, and when the request came in, it was specifying a
host name of
my-virtual-machine-name, which IIS Express didn't know anything about.
The configuration file is located at:
Open it in a text editor and update your site's
bindingInformation value with your virtual
machine's host name:
<site name="MySite" id="1"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="C:\Users\myusername\MySite" /> </application> <bindings> <binding protocol="http" bindingInformation=":8080:my-virtual-machine-name" /> </bindings> </site>
I also removed the leading
* wildcard for good measure.
Now hitting the site from the Mac's browser generated a new error:
503 Service Unavailable
It's a little sad to get excited just because you're seeing a different error, but after a few dozen 400 errors I was happy to see the 503. No idea how to fix it, but it seemed like progress.
After some googling with DuckDuckGo I learned that this error is an indication that IIS
Express doesn't have permissions to handle external requests. Makes sense, since it's designed
to be a lightweight web server that you can set up without having admin rights to your
machine. This article from Microsoft describes the fix, which involves running a command
netsh. I eventually hit a good Stack Overflow post that helped me get the command
To enable external access for your IIS Express site, open cmd or PowerShell as an administrator and run:
netsh http add urlacl url=http://my-virtual-machine-name:8080/ user=everyone
Finally, the stupid obvious step that tripped me up for a while: Restart IIS Express. Just right click on the IIS Express tray icon and click Exit, then relaunch your site in Visual Studio.
Hit the URL
http://my-virtual-machine-name:8080 from your Mac's browser and the site should
load right up.