Nate Pet
Nate Pet

Reputation: 46222

web.config allowDefinition=MachineToApplication error

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>

Upvotes: 9

Views: 110507

Answers (11)

Frankie779
Frankie779

Reputation: 1

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

Upvotes: 0

FLICKER
FLICKER

Reputation: 6683

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.

Upvotes: 0

Kavi
Kavi

Reputation: 191

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>

Upvotes: 1

a.karkar
a.karkar

Reputation: 141

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

Upvotes: 3

amwested
amwested

Reputation: 31

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.

Upvotes: 3

Alberto Trevino
Alberto Trevino

Reputation: 11

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.

Upvotes: 1

SyntaxError
SyntaxError

Reputation: 3859

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

Upvotes: 5

RonaldPaguay
RonaldPaguay

Reputation: 335

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

Upvotes: 0

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.

Upvotes: -3

IrishChieftain
IrishChieftain

Reputation: 15253

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

Upvotes: 11

Ty Petrice
Ty Petrice

Reputation: 1839

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

Upvotes: 3

Related Questions