Tagged: ASP.Net, MONO, Linux
As mentioned in the last session, the biggest pain for Windows developers moving to Mono on Linux is case sensitivity. That session went into detail on how to get around the problem at the Apache level with a mix of human rules (all lower case file and folder naming) and the mod-rewrite module.
Those two practices will take care of all unmanaged resource file lookups, but we're here for Mono .Net coding, right?
Introducing Mono IOMAP
Because the Mono Team knew that most of their new users would be coming over from Windows and usually doing their first tests by dumping some previously written web apps on a Linux box 'just to watch it all fail', they created a one-line compatibility command called Mono IOMAP.
Unfortunately for new users, the setting is not the default (but experienced users would probably not want it bo be). It is turned on at the overall Apache service level by adding the following line to the top of the /etc/apache2/httpd.conf file:
The "all" option forces Mono to do case-insensitive file scans and removes drive names from resource requests. Use the option "case" if that is all you need to handle, and "drive" if that is all you need to handle.
With that one line and a reload/restart of Apache any incorrectly cased user requests for managed pages or *.asmx web services wil be propery routed.
A cool freebie feature IOMAP is that path separator strings are automatically corrected for the OS. So if you have a site folder of "/home/kilgore/sites/asdf/" and image resources are in a subfolder named "/home/kilgore/sites/asdf/resources/imgs/" and your sleepy fingers code a page the Windows way with a reference to <img src="\resources\imgs\prettypic.jpg"> you will see the image in the browser, even though Linux would ordinarily require the link to have the slashes reversed.
If coding mod_rewrite is a little scary to you, then IOMAP may seem great. It is great, don't get me wrong, and that path separator switch feature goes a long way for making existing Windows code work. But it has some limitations.
The 2 big limitations of IOMAP
1) Mono IOMAP is limited to managed resource *file name* searches, not folder name searches. So if a user types a url with a mis-cased path subfolder then they'll get a 404. Also, that 404 will come from Apache, your customError settings in a web.config will be ignored.
2) Mono IOMAP is only for *managed* files. We've said this a few times already but it's important. It will only work for files with extensions that the Mono runtime is in control of.