VS.NET 2005 and the "allowDefinition='MachineToApplication'" error

J

Juan T. Llibre

re:
I'll run into problems if I include Web.config in any directory besides the root,
AND has not been configured as a virtual directory?

You can include web.config in any directory, as long as
that web.config doesn't include any MachineToApplication
configurations, if the directory isn't a virtual directory.

See my just-sent reply.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Juan --

So we're saying the same thing, then? That I'll run into problems if I
include Web.config in any directory besides the root, AND has not been
configured as a virtual directory? And _that_ is what the
MachineToApplication error indicates?


-= Tek Boy =-

re:
Are Web.config files only allowed in virtual directory and IIS website root directories?

You can include a web.config file in every directory you have in your app.

The only warning is that you can't include MachineToApplication configurations
in web.config files in directories which haven't been configured as virtual directories.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Ok, I've made a bit of progress. Before I go into the explanation,
here's my directory structure:

C:\...\tinkering\ (set up as a virtual directory:
http://localhost/tinkering/)
======================================================
\tinkering\GeneralFunctionsAttempt01\
\tinkering\GeneralFunctionsAttempt01\Default.aspx
\tinkering\GeneralFunctionsAttempt01\Default.aspx\Default.aspx.cs
\tinkering\GeneralFunctionsAttempt01\Web.config
\tinkering\FirstPage.aspx
\tinkering\FirstPage.aspx\FirstPage.aspx.cs
\tinkering\Global.asax
\tinkering\Tinkering.sln
\tinkering\Web.config
======================================================

I was trying to run the ASPX script at
http://localhost/tinkering/FirstPage.aspx, so I had opened the
directory in Visual Studio .NET 2005 (File > Open Web Site >
[C:\...\tinkering\] ). When I tried to compile everything (F5), errors
were raised. However, once I excluded
[\tinkering\GeneralFunctionsAttempt01\Web.config] from the project,
everything recompiled again. My guess is that I created the
[GeneralFunctionsAttempt01] project a few days ago, then created the
[FirstPage.aspx] project in the parent folder -- and that might have
caused problems.

Including [\tinkering\GeneralFunctionsAttempt01\Web.config] still
causes compiling [\tinkering] to fail. Are Web.config files only
allowed in virtual directory and IIS website root directories?


-= Tek Boy =-


A day or two ago, I wrote a quick ASPX page with a CS codebehind using
Visual Studio .NET 2005 -- it worked, I saved it and closed the
project. Today, I came back to the project, reopened the solution, and
was greeted with the following error:

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

I did some searching on Google, and all of the solutions to this
problem involved tweaking IIS. The thing is, I didn't have to touch
IIS when I wrote, compiled and ran the ASPX the first time around --
why would I have to do it during a subsequent visit?

If anybody has any suggestions on how to resolve this problem, I would
greatly like to hear them. Thanks in advance!


-= Tek Boy =-
 
G

Guest

To Whom It May Concern --

I was able to resolve my problem (see end of this post) with the help
of Juan T. Llibre, Peter Bromberg and Alvin Bruney. I'm posting a
summary of what the problem was, and how I solved it, in case anybody
else happens across this post.

1) The error message I saw occurred because I had two Web.config files
in my application: one in the root folder (which is OK), and one in a
subfolder (which was causing the problem). Here's what my problematic
Web.config file looked like:

========================================================================
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
========================================================================


2) Everything looks correct. However, I make use of the <compilation>
and <authentication> elements, which is where the "
allowDefinition='MachineToApplication'" error message comes from. At
Juan T. Llibre's direction, I opened up the machine.config file for the
version of the .NET Framework v2.0 I was using: for me, that file was
located at [
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config ].
I then did a string search in that file for [
allowDefinition="MachineToApplication" ], at which point I came across
the following lines of code:

========================================================================
<section name="authentication" type="<snip>"
allowDefinition="MachineToApplication" />
....
<section name="compilation" type="<snip>"
allowDefinition="MachineToApplication" />
========================================================================


3) You'll notice that the "name" property of each of those sections ([
name="authentication" ], [ name="compilation" ] matches the name of
the elements from my Web.config file ( <authentication>, <compilation>
). MSDN documentation ( http://tinyurl.com/y9lyc4 , "allowDefinition >
MachineToApplication" section ) gave me a bit more information about
what that "MachineToApplication" value means:

========================================================================
MachineToApplication - Allows the section to be configured in one of
the following files:

- Machine.config.
- Root Web.config.
- Web.config for an application.

This excludes Web.config files in virtual directories or a physical
subdirectory in the application.
========================================================================


4) The solution, which Juan T. Llibre ended up providing me, was to
remove the <compilation> and <authentication> elements from the
Web.config file in the subdirectory BELOW THE ROOT FOLDER. In my case,
I didn't have a reason to keep that file, so I deleted it, but here's
what it would have looked like:

========================================================================
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>

</system.web>
</configuration>
========================================================================


Thanks to everybody who helped walk me through this Scooby-Doo mystery
over the course a full workday. I really appreciate the help!



-= Tek Boy =-
 
G

Guest

Excellent -- I finally understand what's going on. Thank you again for
your help... I really, really appreciate it.


-= Tek Boy =-

re:
I'll run into problems if I include Web.config in any directory besidesthe root,
AND has not been configured as a virtual directory?

You can include web.config in any directory, as long as
that web.config doesn't include any MachineToApplication
configurations, if the directory isn't a virtual directory.

See my just-sent reply.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Juan --

So we're saying the same thing, then? That I'll run into problems if I
include Web.config in any directory besides the root, AND has not been
configured as a virtual directory? And _that_ is what the
MachineToApplication error indicates?


-= Tek Boy =-

re:
Are Web.config files only allowed in virtual directory and IIS website root directories?

You can include a web.config file in every directory you have in your app.

The only warning is that you can't include MachineToApplication configurations
in web.config files in directories which haven't been configured as virtual directories.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Ok, I've made a bit of progress. Before I go into the explanation,
here's my directory structure:

C:\...\tinkering\ (set up as a virtual directory:
http://localhost/tinkering/)
======================================================
\tinkering\GeneralFunctionsAttempt01\
\tinkering\GeneralFunctionsAttempt01\Default.aspx
\tinkering\GeneralFunctionsAttempt01\Default.aspx\Default.aspx.cs
\tinkering\GeneralFunctionsAttempt01\Web.config
\tinkering\FirstPage.aspx
\tinkering\FirstPage.aspx\FirstPage.aspx.cs
\tinkering\Global.asax
\tinkering\Tinkering.sln
\tinkering\Web.config
======================================================

I was trying to run the ASPX script at
http://localhost/tinkering/FirstPage.aspx, so I had opened the
directory in Visual Studio .NET 2005 (File > Open Web Site >
[C:\...\tinkering\] ). When I tried to compile everything (F5), errors
were raised. However, once I excluded
[\tinkering\GeneralFunctionsAttempt01\Web.config] from the project,
everything recompiled again. My guess is that I created the
[GeneralFunctionsAttempt01] project a few days ago, then created the
[FirstPage.aspx] project in the parent folder -- and that might have
caused problems.

Including [\tinkering\GeneralFunctionsAttempt01\Web.config] still
causes compiling [\tinkering] to fail. Are Web.config files only
allowed in virtual directory and IIS website root directories?


-= Tek Boy =-


(e-mail address removed) wrote:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using
Visual Studio .NET 2005 -- it worked, I saved it and closed the
project. Today, I came back to the project, reopened the solution, and
was greeted with the following error:

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

I did some searching on Google, and all of the solutions to this
problem involved tweaking IIS. The thing is, I didn't have to touch
IIS when I wrote, compiled and ran the ASPX the first time around --
why would I have to do it during a subsequent visit?

If anybody has any suggestions on how to resolve this problem, I would
greatly like to hear them. Thanks in advance!


-= Tek Boy =-
 
J

Juan T. Llibre

re:
Thank you again for your help... I really, really appreciate it.

You're really, really, welcome!

;-)




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Excellent -- I finally understand what's going on. Thank you again for
your help... I really, really appreciate it.


-= Tek Boy =-

re:
I'll run into problems if I include Web.config in any directory besides the root,
AND has not been configured as a virtual directory?

You can include web.config in any directory, as long as
that web.config doesn't include any MachineToApplication
configurations, if the directory isn't a virtual directory.

See my just-sent reply.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Juan --

So we're saying the same thing, then? That I'll run into problems if I
include Web.config in any directory besides the root, AND has not been
configured as a virtual directory? And _that_ is what the
MachineToApplication error indicates?


-= Tek Boy =-

re:
Are Web.config files only allowed in virtual directory and IIS website root directories?

You can include a web.config file in every directory you have in your app.

The only warning is that you can't include MachineToApplication configurations
in web.config files in directories which haven't been configured as virtual directories.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Ok, I've made a bit of progress. Before I go into the explanation,
here's my directory structure:

C:\...\tinkering\ (set up as a virtual directory:
http://localhost/tinkering/)
======================================================
\tinkering\GeneralFunctionsAttempt01\
\tinkering\GeneralFunctionsAttempt01\Default.aspx
\tinkering\GeneralFunctionsAttempt01\Default.aspx\Default.aspx.cs
\tinkering\GeneralFunctionsAttempt01\Web.config
\tinkering\FirstPage.aspx
\tinkering\FirstPage.aspx\FirstPage.aspx.cs
\tinkering\Global.asax
\tinkering\Tinkering.sln
\tinkering\Web.config
======================================================

I was trying to run the ASPX script at
http://localhost/tinkering/FirstPage.aspx, so I had opened the
directory in Visual Studio .NET 2005 (File > Open Web Site >
[C:\...\tinkering\] ). When I tried to compile everything (F5), errors
were raised. However, once I excluded
[\tinkering\GeneralFunctionsAttempt01\Web.config] from the project,
everything recompiled again. My guess is that I created the
[GeneralFunctionsAttempt01] project a few days ago, then created the
[FirstPage.aspx] project in the parent folder -- and that might have
caused problems.

Including [\tinkering\GeneralFunctionsAttempt01\Web.config] still
causes compiling [\tinkering] to fail. Are Web.config files only
allowed in virtual directory and IIS website root directories?


-= Tek Boy =-


(e-mail address removed) wrote:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using
Visual Studio .NET 2005 -- it worked, I saved it and closed the
project. Today, I came back to the project, reopened the solution, and
was greeted with the following error:

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

I did some searching on Google, and all of the solutions to this
problem involved tweaking IIS. The thing is, I didn't have to touch
IIS when I wrote, compiled and ran the ASPX the first time around --
why would I have to do it during a subsequent visit?

If anybody has any suggestions on how to resolve this problem, I would
greatly like to hear them. Thanks in advance!


-= Tek Boy =-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top