none
Error to use a section registered as allowDefinition='MachineToApplication' beyond application level in VS2010

    Question

  • I opened with Visual Studio 2010 a solution with 3 subfolders. One website containing files aspx and cs and the web.config. One WSDL web reference that contains XML files as well as app.config files. And one folder containing cs classes and a csproj file.

    I didn't develop the solution. When I try to build the application I get the following error.

    Error to use a section registered as allowDefinition='MachineToApplication' beyond application level

    I tried to move the web.config (or tjust the configuration part) in the root directory, I tried to modify the authorization type (set to Windows, I tried to set to None). No success. Anybody might help? Thanks

    Thursday, February 02, 2012 10:43 AM

Answers

  • Hi Trinakriae

    This error can be caused by a virtual directory not being configured as an application in IIS.

    you can have web.config file for the sub-directory. However, there are certain properties which cannot be set in the web.config of the sub-directory such as authentication, session state. The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application.

    You can try to specify the location path tags and authorization, as follows:-

    <location path="Admin">
    <system.web>
    <authorization>
    <allow roles="administrators" />
    <deny users="*" />
    </authorization>
    </system.web>
    </location>

    If you wish to have a web.config at the sub-directory level and protect the sub-directory, you can just specify the Authorization mode as follows:-

    <configuration>
    <system.web>
    <authorization>
    <allow roles="administrators" />
    <deny users="*" />
    </authorization>
    </system.web>
    </configuration>

    Thus you can protect the sub-directory from unauthorized access.

    If you still have any further concern about this issue, please post to ASP.NET forum  http://www.asp.net/ for a better support, as it is a asp.net issue instead of the msbuild issue.

    Please mark the useful reply as answer.

    Thank you for your understanding!

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, February 06, 2012 5:28 AM

All replies

  • Hi Trinakriae

    This error can be caused by a virtual directory not being configured as an application in IIS.

    you can have web.config file for the sub-directory. However, there are certain properties which cannot be set in the web.config of the sub-directory such as authentication, session state. The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application.

    You can try to specify the location path tags and authorization, as follows:-

    <location path="Admin">
    <system.web>
    <authorization>
    <allow roles="administrators" />
    <deny users="*" />
    </authorization>
    </system.web>
    </location>

    If you wish to have a web.config at the sub-directory level and protect the sub-directory, you can just specify the Authorization mode as follows:-

    <configuration>
    <system.web>
    <authorization>
    <allow roles="administrators" />
    <deny users="*" />
    </authorization>
    </system.web>
    </configuration>

    Thus you can protect the sub-directory from unauthorized access.

    If you still have any further concern about this issue, please post to ASP.NET forum  http://www.asp.net/ for a better support, as it is a asp.net issue instead of the msbuild issue.

    Please mark the useful reply as answer.

    Thank you for your understanding!

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, February 06, 2012 5:28 AM
  • Hi,

    I have a marked a Virtual Directory, within which a sub-directory is located and is marked as an application in IIS.

    I faced this issue and tried all possiblities. Finally on removing the <authentication mode="Windows"/> from the sub-directory web.config, the issue got resolved. So, basically for the project I have the <authentication mode="Windows"/> given only in the main directory which is the Virual Directory set in IIS.

    My assumption is <authentication mode="Windows"/> when given in the sub-directory (i.e set as application) leads to conflict and is applicable only to the virual directory that is set in IIS.

    Hope this helps !

    Thanks,

    Reena

    • Proposed as answer by Josh Doolan Friday, September 21, 2012 2:03 AM
    • Unproposed as answer by Josh Doolan Friday, September 21, 2012 2:03 AM
    Friday, June 01, 2012 10:29 AM
  • I also faced this issue. Only difference is I was using IIS Express.

    To resolve I simply re-hit:

    "Create Virtual Directory"

    In the Web Settings of my project properties.

    Hope this also helps.

    JD

    EDIT: also forgot to mention you need to delete your obj folder and clean your project.
    • Edited by Josh Doolan Friday, September 21, 2012 3:04 AM
    Friday, September 21, 2012 2:05 AM
  • Hi Lucy-Liu,

    I made website which has admin subfolder, and there are two web.config, one for the main website folder and the other for the admin, I was getting different error which is:

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    As I understand from you solution I deleted the web.config in admin folder, and the only web.config of the website now as:

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
    	<location path="Admin">
    		<system.web>
    			<authorization>
    				<allow roles="Administrator" />				
    				<deny users="*" />
    			</authorization>			
    		</system.web>
    	</location>
    	
        <connectionStrings>        		
    		<remove name="ConnectionString" />	
    		<add name="ConnectionString" connectionString="workstation id=dbname.mssql.somee.com;packet size=4096;user id=username;pwd=pwd;data source=dbname.mssql.somee.com;persist security info=False;initial catalog=dbname;"
                providerName="System.Data.SqlClient" />
        </connectionStrings>	
    	<system.web>
            <authentication mode="Forms" />
            <roleManager enabled="true" />
            <compilation debug="true" targetFramework="4.0" />
    		<customErrors mode="Off"/>
        </system.web>
    	
    	<system.webServer>
    		<defaultDocument>
    			<files>
    				<add value="home.aspx" />
    			</files>
    		</defaultDocument>
    	</system.webServer>
    </configuration>
    

    but I am still getting  same error (error 26), can please you advice me?

    Wednesday, August 14, 2013 8:56 AM
  • Hello Josh where can I find this "Create Virtual Directory" in Visual Studio 2010?
    Wednesday, August 14, 2013 1:13 PM
  • Hi Josh,

    Right click on Your project in Solution explorer and select Properties from the context menu (or click Project in main menu and select "<Your project name> properties..." option.

    New tab containing the project name should appear in main area of VS. In the tab, click Web in in left panel and eventually scroll down a bit in right panel.

    There should be Servers heading and bellow that "Use Local IIS Web server" selected, just bellow, there should be "Project Url:" and on its left side the "Create Virtual Directory" button.

    Simple deleting obj folder and cleaning project (or solution eventually) should be enough though.

    Cheers,

    Matt

    Saturday, November 30, 2013 12:31 PM