You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

You may get this error when trying to browse an asp.net application.

The debug information shows that "This error can be caused by a virtual directory not being configured as an application in IIS."

However, this error occurs primarily out of 2 scenarios.

1. When you create an new web application using visual studio.net, it automatically creates the virtual directory and configures it as an application.
However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and
may get the above error. The debug information you get as mentioned above, is applicable to this scenario.

To resolve it, Right Click on the virtual directory - select properties and then click on "Create" next to the "Application" Label and the textbox. It will
automatically create the "application" using the virtual directory's name. Now the application can be accessed.


2. When you have sub-directories in your application, 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 (you may see that the error message shows the line number where the
authentication or sessionstate is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level
unless the sub-directory is also configured as an application (as mentioned in the above point).

Mostly we have the practice of adding web.config in the sub-directory if we want to protect access to the sub-directory files (say, the directory is admin and we
wish to protect the admin pages from unathorized users).

But actually, this can be achieved in the web.config at the application's root level itself, by specifing the location path tags and authorization, as follows:-

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

However, 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.

Cheers.

Print | posted on Monday, April 25, 2005 7:48 AM

Comments on this post

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Hi,
This helps me solve my problem. Thanks
Left by Jayant Apte on Sep 14, 2005 6:44 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Very nice thread. I have the exact problem. However, this thread does not mention about how to verify if there is a virtual directory created by visual studio. In situaion it seemed that VS didn't create a virtual directory and that has caused a lot of problems. How do I get VS to create them and set it to Application? I have gone to the ASP.NET website forum but it seemed they were clueless about this issue. No one has answered my question yet. So I hope someone in here will answer this question for me. Many thanks in advance.
Left by myChucky on May 19, 2006 10:51 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Thank! Helped me.
Left by KJH on May 19, 2006 7:10 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
hi it really helped me to solve my problem thanQ
Left by prem on Aug 03, 2006 3:01 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Nice Work!
What if we remove the authentication in the web.config file.
<!-- <authentication mode="Windows"/>-->
What will be the effect on the Authentication then ?
Left by Umair Khan on Aug 20, 2006 8:13 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Thanks alot this every other site, just mentions #1. My problem was #2...

Thanks again..
Left by Renum on Oct 07, 2006 12:39 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Thanks a lot. Your explanation in #2 solved my problem!
Left by ed on Dec 20, 2006 4:02 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
In authentication error, will the code you suggested replace <!-- <authentication mode="Windows"/>-->? If not, just where should the code be placed, before or after this line?

Thanks!
Left by Helen on Feb 13, 2007 2:59 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
I'm having a problem with my web.config with virtual directories
My problem is at the configurationstrings node.
I have a running 2.0 site and i want to configure anoter site as virtual directy under this site
like this
|Site A (2.0)
|-Projects (virtual directory)
|-|- Site B (2.0)

What is my problem?
In Both sites I use a ddl for my datalayer.
In the webconfig of site A I set the connectionstring of this ddl to the correct database A.
site A web.config:
<connectionStrings>
<add name="company.configuration.SQLConnection" connectionString="correct datasource to database A" />
</connectionStrings>

I do the same for site B (same name, except to database B)
I first clear the connectionstring and even do a remove!
<connectionStrings>
<clear/>
<remove name="company.configuarion.SQLConnection"/>
<add name="company.configuarion.SQLConnection" connectionString="correct datasource to database B" />
</connectionStrings>

as I run my website A at location www.siteA.com, there is no problem.
As I run website B at location www.siteA.com/projects/siteB he is still getting the values from database A (even I have updated this in the webconfig)

How can I solve this so that for Site B he accually takes the values from the connectionstring B

Thanks in advance
Left by Kimage on Mar 16, 2007 1:29 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Hi,

Thanks for your valuable research and display here.

I was scratching my head to resolve this problem. Fortunately I found this and rectified my problems.

An Indian
Left by cdm on Sep 07, 2007 10:00 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
/me slaps his head

Thanks! Scenario number 2 for me.
Left by Sander on Oct 19, 2007 9:16 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Nice article. Sadly I still have the problem - am using IIS7 though. Oh, I long for Apache!
Left by Dave on Nov 24, 2007 6:25 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Thanks! No. 2 worked for me :-)
Left by Cristina on Jan 20, 2008 5:22 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Hi none of the solutions helped me.

In my case, I had a fully working application and later i had coppied the application to another folder as root....
Root <New Folder>
--> Application Folder
-- Files with in the folder

After copping the application folder to New root Folder, this error is bieng displayed. In fact if i am rt. clicking Root folder directory a Property page is oppening where i am not able to find
Right Click on the virtual directory - select properties and then click on "Create" next to the "Application" Label and the textbox.

Can you give me any solution for this...
Left by Jats on Jan 21, 2008 9:59 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
You are absolutely right. thanks a lot. It's every useful.
Left by Joe on Mar 26, 2008 11:30 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
I was wondering how to resolve this problem, then i got through your thread, it saved my time
Left by Lokesh on Apr 10, 2008 10:05 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Totally solved my problem - Thanks so much for an well-written, easy to follow article!
Left by H-Bomb on Apr 17, 2008 4:09 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
your help was great. I have been looking for this solution for two days.
Left by Kathir U on Apr 18, 2008 10:57 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Thank you, it helped me solve my problem!

If only MS would have such support level...
Left by laurentiu on Jun 13, 2008 1:33 AM

# allowDefinition='MachineToApplication' beyond application level" in asp.net

Requesting Gravatar...
Well, neither scenario works for me. I moved my project over to a new machine. Set up the virtual directories but to no avail. I get the same error. When I start without debugging, the app dies on the authentication = windows line in the webconfig. I thought I could move a project to a new machine, set up a virtual directory, and debug. No such luck. Any insight?
Left by Bill on Aug 04, 2008 1:16 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition

Requesting Gravatar...
thanks for this. solved my problems when trying to recreate my sites on a new server.

now i'm up and running again.

Thanks
Left by Derek Hosewood on Sep 07, 2008 8:49 PM

# re: You may

Requesting Gravatar...
thanks again
quick loans
Left by Derek Hosewood on Sep 07, 2008 8:50 PM

# Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application le

Requesting Gravatar...
NOT FOUND THE OPTION "CREATE" WHILE RIGHT CLICKING-> SELECT PROPERTIES-> "Create" next to the "Application" Label and the textbox

Left by RAHUL on Feb 22, 2009 4:35 PM

# That's quite nice

Requesting Gravatar...
I created virtual directory and mapped to application.Then am trying to build the application, am getting this error message.
"It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. "
Left by Casinoregel on Apr 02, 2009 6:15 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
<authorization>
<allow roles="administrators" />
<deny users="*" />
</authorization>

What do I put in the "administrators"?
Left by bern on Jun 07, 2009 5:38 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
Just today faced this issue. Timely got this solution.

Thanks.
Left by Muruganantham Durairaj on Jun 13, 2009 12:38 PM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
This article helped me.
Thanks!
Left by Ekki on Dec 23, 2009 12:59 PM

# Quite a different cause - Web Project vs Web Site

Requesting Gravatar...
This post gave me the clue that I had extra web.config files. This is a website which I created from a visual studio web project (still haven't got my head round the difference). I deleted the project and obj folders and their contents and the website then built successfully.

Thanks!
Left by Stephen Solt on Apr 15, 2010 12:19 AM

# re: You may receive the error "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond appli

Requesting Gravatar...
In my case, I brought in an project that needed upgraded to my new version of VS 2010. It created a backup, and that backup directory was throwing off my build. When I removed the backup directory, my errors vanished.
Left by Donnie Wishard on Apr 22, 2010 2:55 PM

Your comment:

 (will show your gravatar)