web.config allowDefinition=MachineToApplication error
Asked Answered
I

11

9

Under the root directory I have the following structure

..
..
..
web.config
Report Folder
- Login.aspx
- Web.config
  |
  |-> ViewReport
       |       
       |-> Report.aspx

In my web.config file in the Report folder I have the following:

    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <authentication mode="Forms">
                <forms loginUrl="Login.aspx" defaultUrl="ViewReport/Report.aspx">
                    <credentials passwordFormat="Clear">
                        <user name="Johl" password="pass888"/>
                    </credentials>
                </forms>
             </authentication>
         </system.web>

        <location path="ViewReport/Report.aspx">
            <system.web>
                <authorization>
                    <allow users="Johl"/>
                    <deny users="*"/>
                </authorization>
            </system.web>
         </location>
     </configuration>

When I start debugging I get the following 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.

NOTE that in my root web.config I have something like the following:

In my root, I already have the following:

         <system.web>        
            <authentication mode="Forms">
                <forms loginUrl="Str/StrUserLogin.aspx" timeout="2880" slidingExpiration="true"  />         
               </authentication>
            <authorization>
                <allow users="*" />
            </authorization>     
         </system.web>
Ischia answered 30/4, 2013 at 19:1 Comment(3)
Did you creating a virtual directory at the site root?Trotter
Do I do this even if I am working on localhost?Ischia
Yes, this is probably the cause of this error.Trotter
T
11

Create a virtual directory at the site root. This can be done via project properties in VS under the Web tab.

It's also possible that you have things defined in the sub-directory that should be in the root config file. See similar question here:

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

Trotter answered 30/4, 2013 at 19:20 Comment(3)
Thanks. I have a web.config in the root and the sub directory. Based on what you mentioned below, why am I getting this error message then?Ischia
Did you create the virtual directory? I've updated my answer.Trotter
I have a Web API which is in the wwwroot folder and locally accessible within the network. I can execute api calls like this: http://mylocalapi:133/api/Values/Get and I get a result. I have an external site which is http://example.org and I would like to execute the same http://mylocalapi:133/api/Values/Get. How can I do that? #43002783Kulp
N
5

Converting your folder/project into an application in IIS can resolved this error.

Nissie answered 12/1, 2017 at 13:26 Comment(1)
This helped me. Thanks ! :)Language
B
3

The contents of the web.config in the subdirectory should be placede in the root directory. The configuration in the subdirectory is making IIS treat the subdirectory as the application root but it is not the application root. This is why you get the error allowDefinition='MachineToApplication'.

Bituminous answered 30/4, 2013 at 19:20 Comment(1)
Thanks typetrice. I updated what I have in the root web.config. Not sure how to combine what I have in the subdirectory to what is in the root web.config. Please helpIschia
A
3

This error seems to occur if you try to open an asp.net WEBSITE and run it while it was originally encapsulated by a SOLUTION. Do this: Close the website, find the related solution (.sln-file) further up in the file system and open this in stead. Inside the solution you will now be able to use your website without getting this error.

It would be nice if Microsoft could guide people in the right direction when they get lost in asp.net like this. The present error message about allowDefinition=MachineToApplication is not understandable for normal humans like me.

Agnomen answered 18/7, 2018 at 10:45 Comment(0)
F
3

If you put the published files in inetpub/wwwroot/../ Make sure to add the root folder as an application in IIS Manager.

enter image description here

Fifth answered 18/12, 2019 at 18:8 Comment(1)
This was actually the only thing that helped me.Braque
B
1

I deleted my bin and obj folder for the project and then rebuilt the solution and everything was working fine...not a technically savvy answer but it works.

Betwixt answered 14/3, 2018 at 20:37 Comment(1)
This was actually the only thing which helped me. +1Kendall
P
1

Just add this below lines in your csproject file to clean up the obj/bin folder automatically.

<Target Name="BeforeBuild">
  <!-- Remove obj folder -->
  <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
  <!-- Remove bin folder -->
  <RemoveDir Directories="$(BaseOutputPath)" />
</Target>
Pydna answered 9/12, 2020 at 10:21 Comment(1)
This was the only one that solved it here! Tks +1Mcclelland
L
0

I opened the web site from IIS instead of file system and it worked.

Ly answered 27/9, 2015 at 3:23 Comment(0)
R
0

In my case, my website was working before deploying the new version.

I found an incorrect Web.config inside Views folder. I replaced it with original file and the problem resolved.

Rhonda answered 21/3, 2022 at 23:16 Comment(0)
M
0

This may help someone, I had this error for about a week spent 30 hrs trying to get the website to load. I had the main web.config file in the correct top level directory, with a minor roles only web.config in a sub folder no clashes. This error "a virtual directory not being configured as an application in IIS" can also occur if your website is sharing an Application Pool in IIS, and this can prevent 2 websites from the same pool opening up simultaneously (e.g on 2 different browsers, the 1st opens up and the 2nd gives an error 'an internal server error has occurred') and similar useless error messages. changing the URL to http://127.0.0.1 loopback didn't help, it just suggested a permissions error on the web.config file, but that was a red herring. My advice, and how this got solved eventually, is to make sure in IIS that your website has its own Application, is using an Integrated pipeline mode and a LocalSystem identity but above all make sure it is not sharing an Application Pool with another website. After hours and hours of trying to match up the web.config file with IIS and various other permissions, and hundreds of dead end error messages this fixed it for me. Hope this helps someone..

Melainemelamed answered 6/8, 2024 at 13:2 Comment(0)
E
-3

This error occur if your web.config file and your all aspx file are not in the same folder. so please put all the files in the same folder.

Thanks.

Eatable answered 17/4, 2015 at 6:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.