An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

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

Monday, April 25, 2005 7:48 AM
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.

Feedback

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

Hi,
This helps me solve my problem. Thanks 9/14/2005 6:44 AM | Jayant Apte

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

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. 5/19/2006 10:51 AM | myChucky

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

Thank! Helped me. 5/19/2006 7:10 PM | KJH

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

hi it really helped me to solve my problem thanQ 8/3/2006 3:01 AM | prem

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

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 ?
8/20/2006 8:13 AM | Umair Khan

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

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

Thanks again.. 10/7/2006 12:39 AM | Renum

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

Thanks a lot. Your explanation in #2 solved my problem! 12/20/2006 4:02 PM | ed

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

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! 2/13/2007 2:59 PM | Helen

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

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
3/16/2007 1:29 PM | Kimage

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

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 9/7/2007 10:00 PM | cdm

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

Thanks !!!

You solve my problems. 10/2/2007 2:52 PM | pb

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

/me slaps his head

Thanks! Scenario number 2 for me. 10/19/2007 9:16 AM | Sander

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

Nice article. Sadly I still have the problem - am using IIS7 though. Oh, I long for Apache! 11/24/2007 6:25 AM | Dave

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

Thanks! No. 2 worked for me :-) 1/20/2008 5:22 AM | Cristina

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

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... 1/21/2008 9:59 PM | Jats

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

You are absolutely right. thanks a lot. It's every useful. 3/26/2008 11:30 AM | Joe

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

I was wondering how to resolve this problem, then i got through your thread, it saved my time 4/10/2008 10:05 PM | Lokesh

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

Totally solved my problem - Thanks so much for an well-written, easy to follow article! 4/17/2008 4:09 AM | H-Bomb

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

your help was great. I have been looking for this solution for two days. 4/18/2008 10:57 PM | Kathir U

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

thanks for the post. helped me figure out what this error meant. 5/20/2008 3:27 AM | tom

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

Thank you, it helped me solve my problem!

If only MS would have such support level... 6/13/2008 1:33 AM | laurentiu

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

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? 8/4/2008 1:16 AM | Bill

#  <authentication mode="Windows" />

my asp.net project is running in my local pc also in my localhost good. but when i hosted my applicationb in http server as an application the following error is displaying...

Server Error in '/' Application.
--------------------------------------------------------------------------------

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser 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.

Source Error:


Line 23: -->
Line 24:
Line 25: <authentication mode="Windows" />
Line 26: <authorization>
Line 27: <allow users="*" />


Source File: c:\sites\premium19\stepmediabd\webroot\testasp\web.config Line: 25


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2407; ASP.NET Version:1.1.4322.2407




PLZ HELP ME.. 8/16/2008 4:37 AM | rain

Post a comment





 

Please add 1 and 2 and type the answer here: