When deploying an ASP.NET application under Mono/Apache on Ubuntu, I encountered peculiar behavior where requests to /icons
returned a directory listing instead of being processed by my ASP.NET handlers. This didn't occur with other similar paths like /images
. Here's what I discovered:
Apache HTTP Server comes with several predefined aliases in its default configuration. The /icons/
path is one such special case. In the default apache2.conf
or httpd.conf
, you'll often find:
Alias /icons/ "/usr/share/apache2/icons/"
<Directory "/usr/share/apache2/icons">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
To verify if this is affecting your setup, check:
# Check loaded modules
apache2ctl -M | grep alias
# Check active aliases
grep -r "Alias /icons/" /etc/apache2/
For ASP.NET applications, you'll want to disable or override this alias. Here are two approaches:
Method 1: Remove the Alias Completely
# In your apache configuration:
<IfModule alias_module>
# Comment out or remove the icons alias
# Alias /icons/ "/usr/share/apache2/icons/"
</IfModule>
Method 2: Create Custom Location
# In your virtual host configuration:
Alias /icons/ "/var/www/your_asp_app/icons/"
<Directory "/var/www/your_asp_app/icons">
Options -Indexes
AllowOverride None
Require all granted
SetHandler mono
AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx
</Directory>
After making changes, test with:
sudo apache2ctl configtest
sudo systemctl restart apache2
Then access /icons
in your browser - it should now be processed by your ASP.NET application rather than showing a directory listing.
The /images
path typically doesn't have a predefined alias in Apache's default configuration, which explains why it behaves as expected. This difference highlights why special paths like /icons
, /manual
, or /cgi-bin
require extra attention in Apache configurations.
When deploying ASP.NET applications via Mono on Apache2/Ubuntu, you might encounter unexpected behavior with specific paths like /icons
. While most routes correctly trigger your ASP.NET handlers, some special paths default to Apache's built-in directory listings.
Apache HTTP Server comes with several preconfigured aliases for common directories. One such default alias is:
Alias /icons/ "/usr/share/apache2/icons/"
This explains why /icons
shows a directory listing while your custom /images
directory works normally. The /icons
path is being intercepted by Apache before reaching your Mono handlers.
To check if this is the case in your setup:
grep -r "Alias /icons" /etc/apache2/
There are two effective approaches to resolve this:
Option 1: Remove the Alias Completely
# In your apache config or virtual host: <Directory "/usr/share/apache2/icons"> Options -Indexes </Directory> Alias /icons "/path/to/your/actual/icons"
Option 2: Use Location Directive
<Location "/icons"> SetHandler mono DirectoryIndex default.aspx </Location>
If you can modify your application, consider renaming the problematic path:
// In your ASP.NET routing configuration routes.MapRoute( name: "Icons", url: "assets/icons/{filename}", defaults: new { controller = "Resources", action = "GetIcon" } );
To verify which paths are being intercepted by Apache before reaching Mono:
apache2ctl -S 2>&1 | grep Alias