Disclaimer

Any opinions expressed here are my own and not necessarily those of my employer (I'm self-employed).

May 17, 2011

Serving pac files from IIS

IIS refuses to serve static files that cannot be mapped to a particular MIME type. Since I'm a Windows n00b I spent some time figuring this out for myself. Here's what happened, and how to deal with it.

I tried to serve a proxy.pac file from the IIS on my localhost (IIS 7.5/Windows 7), to test some changes to a proxy auto-configuration script. IIS gave me a 404 error instead of serving the file. After fiddling about with various security settings for quite some time, I was eventually able to figure out the problem. If IIS lacks a configured MIME type for a file then it will refuse to serve it — returning a 404 error instead. I suspected MIME types could have something to do with it after I found out that IIS happily served the file as a regular text file if the file was named proxy.txt. As always with Microsoft, when you've successfully pinpointed the problem yourself, you're finally able to launch a Google search that reveals something useful...

Turns out it's all documented, e.g. in the article with the catchy title: Error message when users visit a Web site that is hosted on a server that is running Internet Information Services 7.0: "HTTP Error 404.3 - Not Found". Note, Microsoft states that users visiting the web site will get an error message indicating that the problem is caused by the missing MIME map policy. For the record, I've tested multiple browsers, IE9, FF4,Chrome, Opera. Neither showed a useful error page, so IIS 7.5 does not serve such a page by default.

So, the file exists and you get the generic 404. How can you verify the problem? If you look in the IIS log file you'll see something similar to this (I've truncated the user agent):
GET /proxyx.pac - 8000 - ::1 Mozilla/5.0+(compatible;+MSIE+9.0;.....) 404 3 50 1
Note the status codes: 404 3. These are the clues Microsoft has left for you on your quest to serve a static file from IIS. That's unless you, like me, find that you do not have any log files. In that case you should check out my latest post: Enabling IIS log files on Windows 7.

Fortunately, the problem is easily fixed. To add a MIME type for the proxy.pac go to the IIS Manager and select the website. On the settings screen, you'll see the "MIME Types" in the IIS section. There you can "Add.." new MIME types.

According to Wikipedia, there are two MIME types in use for PAC files. I used the newer of the two: application/x-javascript-config.


That's it. IIS should now serve the file, with the correct MIME-type.

2 comments:

  1. Thanks - I was really puzzled by this error and even trying a new virtual website serving just this one file had no effect.

    ReplyDelete
  2. Thanks, helped me lot.

    ReplyDelete

Copyright notice

© André N. Klingsheim and www.dotnetnoob.com, 2009-2015. Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to André N. Klingsheim and www.dotnetnoob.com with appropriate and specific direction to the original content.

Read other popular posts