Y'herd thisun? 

“'Everyone wants to eat like an American on this globe,' said Daniel Basse of AgResource, a Chicago consultancy. 'But if they do, we're going to need another two or three globes to grow it all.'”

from As world's appetite soars, so do food bills by David Streitfeld

MONO/Ubuntu part 14 - Managed cAse sensitiviTy

TaggedASP.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:

    MonoSetEnv MONO_IOMAP=all

    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.

    It's the same as Microsoft ASP.Net running under IIS. Thing is that we deal with it in Windows all the time and tend to forget about how we fix it in our sleep. When it comes up in Mono, it can create fear of the platform ... but it's the same thing and has the same fixes.

    If a user requests an *.html file from your webapp and it doesn't exist then a 404 error page will only be returned if you have told *IIS* what the 404 page is. Setting a 404 page in the ASP.Net web.config file is useless for requests for un-managed file extensions.

    Some folks get around this in IIS by mapping unmanaged extensions (html, htm. gif, jpg, etc.) to be handled by ASP.Net. You can do that with Mono too. You create an HttpHandler, same as in Windows, tell Apache to pass requests for the extension to Mono by adding the extension to the /etc/apache2/mods-available/mod_mono.conf or httpd.conf or (with a new Location node) in individual Virtual Host files and then, as in Windows, you add an httpHandler node to the application's web.config. For an oldie and goodie on that, click here. 

    The takeaway here is that even if you and your crew always save files lower cased and even if you always create folders lower cased and even if you always type page code paths correctly Mono IOMap alone can bite your users who have no paycheck-need to type stuff correctly.

    Internet users won't tell anyone that a page doesn't work, they'll just surf off to find another site. And IntrAnet users hitting a single 404 will tell Everyone but you that your whole app is useless because of your world-killing terrible "bug" :-).

    So whAt's thE aNSwer?

    Use them both.mod_rewrite takes care of unmanaged file requests and forcing subfolders to lower case and Mono IOMAP takes care of the managed file requests.

    Coming up: Forbidding files and directory lists. Then as a bonus, installing and using a corporate-trusted database server.

    jump to:

  • 1: Why?
  • 2: Installation
  • 3: Update the OS with APT
  • 4: Remoting to the box with SSH
  • 5: NANO quickies for 95% of the jobs
  • 6: Firewalling Ubuntu 8.10 Server
  • 7: Installing Apache2 and MONO
  • 8: Test client host files
  • 9: Configure MONO on Apache2
  • 10: Apache default pages
  • 11: Handling Apache and Mono Errors
  • 12: Subdomains and Christian porn
  • 13: Virtual Host Tweak: unmanaged cAse sensitiviTy
  • 14: Managed cAse sensitiviTy
  • 15: Managing files and folders
  • 16: Logging Apache Accesses and Errors
  • 17: Ubuntu Task Managers
  • 18: Ubuntu Services and Service Managers
  • 19: Installing Oracle 10g XE Server
  • 20: Connecting Mono to Oracle

  • home     who is smith    contact smith     rss feed π
    Since 1997 a place for my stuff, and it if helps you too then all the better