Bug 2345 - Sub application may cause a "MachineToApplication" warning
Summary: Sub application may cause a "MachineToApplication" warning
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Configuration ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-12-05 13:53 UTC by QuickJack
Modified: 2011-12-13 03:03 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description QuickJack 2011-12-05 13:53:28 UTC
A web application may have it's physical directory located below another web application:

physical path             virtual path
/var/www/app1             /app1
/var/www/app1/app2        /app2

This is generally working in Mono. However, if both applications define an <authentication> section within their web.config files, Mono does not work right. It displays a warning page when accessing app1 via a browser.

The same scenario works in the following cases:
WinXP/IIS
WinXP/mod_aspdotnet
Comment 1 QuickJack 2011-12-05 14:10:38 UTC
I have tested the behaviour with Mono 2.11/master

The exception is basically caused at System.Configuration.SectionInfo.ReadData().
Starting at line 180 there's the following code:

if (!config.ConfigHost.IsDefinitionAllowed (config.ConfigPath, allowDefinition, allowExeDefinition)) {
object ctx = allowExeDefinition != ConfigurationAllowExeDefinition.MachineToApplication ? (object) allowExeDefinition : (object) allowDefinition;
throw new ConfigurationErrorsException ("The section <" + Name + "> can't be defined in this configuration file (the allowed definition context is '" + ctx + "').", reader);
}

The call to System.Configuration.InternalConfigurationHost.IsDefinitionAllowed() returns false which seems to be wrong. Overall this function looks incomplete:

public virtual bool IsDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
		{
			switch (allowDefinition) {
				case ConfigurationAllowDefinition.MachineOnly:
					return configPath == "machine";
				case ConfigurationAllowDefinition.MachineToApplication:
					return configPath == "machine" || configPath == "exe";
				default:
					return true;
			}
		}

In the MachineToApplication case it allows machine configurations and exe configurations. It should also allow web application based configurations.
Comment 2 QuickJack 2011-12-07 16:07:55 UTC
My assumption about System.Configuration.InternalConfigurationHost class was wrong. The problem is caused in System.Web.Configuration.WebConfigurationHost class. IsDefinitionAllowed() is not working correctly.

Additional web.config files below the directory tree of an application are allowed if and only if they belong to a sub application. But WebConfigurationHost does not provide the functionality to determine if the current configPath belongs to a valid web app or not. As a result, IsDefinitionAllowed() returns false in case there is a sub application below the directory tree of an existing application.

WebConfigurationHost seems to be missing some functionality.
Comment 3 QuickJack 2011-12-12 07:26:22 UTC
The defintion "MachineToApplication" means that a section can only be inherited from machine.config to web.config of an existing application. It cannot be inherited from an application to a sub application. Thus, it is allowed to define those sections for sub applications. But it is forbidden to define those sections in web.config files located in virtual sub directories.

Let's take the authentication section as an example. This section is here to define basic authentication settings and to allow an application to find login.asox. An application as well as their sub applications must define an authentication section because this section cannot be inherited. If this schema would not work, we would not be able to use authentication in this case.


https://github.com/QuickJack/mono/commit/3a604b81c5cf6f2d511fb1da02ad80fc929b9bfe provides a partial fix for the issue. IsDefinitionAllowed() calls IsApplication() to determine if the given path points to the root of an existing web application. Currently IsApplication() simply returns true. This code allows sub applications to use ASP.NET authentication which is working in .NET framework since the very first release of Version 2.0 a few years ago.
Comment 4 Marek Habersack 2011-12-13 03:03:15 UTC
Fix merged with master in 694ab7d8477ba306f75ee1cb71ec8acd87788f67, thanks!