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>
Nate Pet
  • 44,246
  • 124
  • 269
  • 414

10 Answers10

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

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91
  • 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? – Nate Pet Apr 30 '13 at 20:57
  • Did you create the virtual directory? I've updated my answer. – IrishChieftain Apr 30 '13 at 21:13
  • 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? http://stackoverflow.com/questions/43002283/how-to-allow-internal-mvc-web-api-from-external-site-outside-the-network – Si8 Mar 24 '17 at 14:41
5

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

SyntaxError
  • 3,717
  • 6
  • 30
  • 31
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'.

Ty Petrice
  • 1,769
  • 1
  • 13
  • 7
  • 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 help – Nate Pet Apr 30 '13 at 19:24
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.

amwested
  • 31
  • 4
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

a.karkar
  • 141
  • 1
  • 7
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.

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>
Kavi
  • 181
  • 1
  • 6
0

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

RonaldPaguay
  • 337
  • 3
  • 12
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.

FLICKER
  • 6,439
  • 4
  • 45
  • 75
-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.