• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • Last Modified:

I am getting an error in the web.config file?

Hi,

I am using ASP.NET 2.0 - c#

I am getting an error in the web.config file. Please can someone show me how to fix 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.C:\Documents and Settings\user\My Documents\Visual Studio 2005\WebSites\Computer Store\web.config      33      

<?xml version="1.0"?>
 
<configuration>
 
  <appSettings>
    <add key="SiteName" value="Computer Store"/>
  </appSettings>
 
  <connectionStrings>
    <add name="ComputerStoreConnection" connectionString="MyConnection" 
       providerName="System.Data.SqlClient"/>
  </connectionStrings>
 
  <!--Only administrators are allowed to access CatalogAdmin.aspx-->
  <location path="CatalogAdmin.aspx">
 
    <system.web>
 
      <compilation debug="true" defaultLanguage="c#" />
      <pages theme="ComputerStoreDefault"/>
 
      <authentication mode="Forms">
        <forms name="ComputerStoreLogin" loginUrl="Login.aspx" 
          timeout="60" />
      </authentication>
 
      <roleManager enabled="true" />
      <authorization>
        <allow roles="Administrators"/>
        <deny users="*"/>
      </authorization>
 
      <customErrors mode="On" defaultRedirect="Oooops.aspx"/>
 
    </system.web>
 
  </location>
 
</configuration>

Open in new window

0
vielkacarolina1239
Asked:
vielkacarolina1239
  • 11
  • 9
1 Solution
 
SteveH_UKCommented:
In IIS, you configure a website to run as an application in order to use ASP.NET.  This is normally completed at the website level.  However, you can also make this change at other folders by clicking the Create Application button on the folder's Home Page tab (in IIS).

This error is caused by having this line:

<customErrors mode="On" defaultRedirect="Oooops.aspx"/>

In a web.config that is in a folder other than one that is defined as a starting point for an application.

You have two choices:

1)  Configure the folder where the web.config file is to be an application starting point in IIS.  See here for an example http://www.cryer.co.uk/brian/mswinswdev/ms_vbnet_vb_not_configured_as_app.htm
2)  Move this line out of this web.config and place it in the web.config at the root of the website

0
 
svcoderCommented:
Take a look at this post for some good explainations of this error and the possible causes.

http://geekswithblogs.net/ranganh/archive/2005/04/25/37609.aspx
0
 
vielkacarolina1239Author Commented:
Hi, I commented the line of code you refered above. I still get the same error. The Oooops.aspx page is at the same directory level as the web.config file. However I commented these lines of code:

 <!--<location path="CatalogAdmin.aspx">-->
  <!--</location>-->

and the web.config file works with out errors. However, I cannot commet these lines of code because I redirect Administrators to CatalogAdmin.aspx page after the logged into the system using this piece of code.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
SteveH_UKCommented:
Can you confirm whether the error was referring to the same line or a different one?

Is the web.config file at the root of the website?  Are you using IIS or the ASP.NET development server?  Did you make the folder an application root in IIS?

Have a look at the article provided by svcoder.  Note that it describes how to use the location tags for this purpose in the application's root web.config file.

Note as well that there was no need to move the Oooops.aspx file.
0
 
vielkacarolina1239Author Commented:
Yes, the web.config file at the root of the website.

I am using ASP.NET development server
0
 
vielkacarolina1239Author Commented:
The error was refering to the same line.

Do I need to use IIS instead of ASP.NET development server?
0
 
SteveH_UKCommented:
There can be problems with the ASP.NET development server.  Using IIS is far more reliable.

See here http://www.codeprof.com/dev-archive/217/9-31-2173911.shtm for an example issue with the development server.
0
 
vielkacarolina1239Author Commented:
So, should I create a virtual directory in IIS for my application?

If I create an IIS virtual directory, does that means that I would have to register a domain name?

I am using XP, please, can you refer me to a link were I can learn how to configure IIS for my application?

Also, when I created the website, I created the website as a File System. Should I create the website as a HTTP website so that it would work with IIS or can I use the one that I already have as a File System?
0
 
SteveH_UKCommented:
>So, should I create a virtual directory in IIS for my application?
This is the simplest solution, yes.

>If I create an IIS virtual directory, does that means that I would have to register a domain name?
No.

>I am using XP, please, can you refer me to a link were I can learn how to configure IIS for my application?
Have a look at this article: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_16391&sliceId=2

See this for basic configuration and troubleshooting of your ASP.NET configuration http://msdn2.microsoft.com/en-us/library/t6dbcb8d(VS.71).aspx

>Also, when I created the website, I created the website as a File System. Should I create the website as a HTTP
>website so that it would work with IIS or can I use the one that I already have as a File System?
You can use the folder for the virtual directory in IIS.  You do not need to change your project.
0
 
vielkacarolina1239Author Commented:
thanks a lot. I am going over the material you refered me to.
0
 
SteveH_UKCommented:
OK.
0
 
vielkacarolina1239Author Commented:


I think I Know how to configure IIS.

THis is what I did:

1)right click Default Web Site

2)Go to New and clicked Virtual Directory

3)Give a name to the alias

4)For the website path, I browse to the
  website directory:
C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store

5)set the access permissions to Read and Run scripts

6)clicked finished


After creating the Virtual Directory I right clicked on
Default Web Site and clicked properties

1)in the Web Site tab, I set the IP Address to my network card IP Address

2)in Home Directory tab, I set the Local Path to my website path
C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store


3)in Documents tab, I set the default content to my ASP page


4)In ASP.NET tab, I set ASP.NET version to 2.0.50727
   A)clicked Edit Global Configuration in ASp.NET tab
      a)clicked Authentication tab and set Authentication mode to Forms
      b)clicked Application tab and set page language default to c#
      d)clicked apply and then Ok to exit ASP.NET Configuration Settings

5)I clicked apply an then Ok to exit the Default Web Site Properties windos

6) Stop the service, and refresh the Default WebSite. Restart the service and right click on the Virtual directory and clicked browse.

After clicking browse, I am getting the following error message in IIS
System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.







After setting the Default Web Site properties,
I right click my virtual directory and clicked the properties



1)in the Virtual Directory tab,
A)I set the Local Path to
  C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store
B) I checked the Read permision
C) Clicked the create button to create the application
D) Set Execute Permissions to Schipts only

2)In the Document tab, I added my ASP Default page and move it up


3)In the ASP.NET tab, I set ASP.NET version to 2.0.50727










0
 
vielkacarolina1239Author Commented:
However, I am getting the followin error in IIS

System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.

Also, the error page gives me this link
http://support.microsoft.com/?kbid=267904.

I went to the above link and downloaded the file Metaacl.vbs. I placed the file inside C:\Inetpub\AdminScripts as instructed in the article

to run Metaacl.vbs one needs to open a Command Prompt and type
c:\Inetpub\Adminscripts>cscript metaacl.vbs IIS://LOCALHOST/W3SVC mydomain\mydomainaccount RW

RW will give the read and write permissions to mydomain\mydomainaccount.

My question is, what should I use for mydomain\mydomainaccount?

the computer that I am working on is a stand alone computer and is not under a domain.
Should mydomain be the computer name and mydomainaccount be the user logged into the computer?


0
 
SteveH_UKCommented:
>THis is what I did:
>1)right click Default Web Site
>2)Go to New and clicked Virtual Directory
>3)Give a name to the alias
>4)For the website path, I browse to the
> website directory:
>C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store
>5)set the access permissions to Read and Run scripts
>6)clicked finished

Good so far.

>After creating the Virtual Directory I right clicked on
>Default Web Site and clicked properties
>
>1)in the Web Site tab, I set the IP Address to my network card IP Address
This is okay, but the default of "all unassigned addresses" is fine too.

>2)in Home Directory tab, I set the Local Path to my website path
>C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store
You don't need to do this if you have created a virtual directory.

>3)in Documents tab, I set the default content to my ASP page
You shouldn't need this.

>4)In ASP.NET tab, I set ASP.NET version to 2.0.50727
>   A)clicked Edit Global Configuration in ASp.NET tab
>      a)clicked Authentication tab and set Authentication mode to Forms
>      b)clicked Application tab and set page language default to c#
>      d)clicked apply and then Ok to exit ASP.NET Configuration Settings
You should set these on the virtual directory, if you are using one, not on the website root.  Both are acceptable, but if you are using a virtual directory they should be set there.

>5)I clicked apply an then Ok to exit the Default Web Site Properties windos
>
>6) Stop the service, and refresh the Default WebSite. Restart the service and right click on the Virtual directory and clicked browse.
>
>After clicking browse, I am getting the following error message in IIS
>System.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.

You need to create an application at the virtual directory level, the same way you configured it at the website root, but do so at the virtual directory.  You'll need to use the Create Application button.

I'd recommend that you change the root back to using C:\inetpub\wwwroot and that you unconfigure ASP.NET from the root if you are using a virtual directory, although you do not have to do so.





After setting the Default Web Site properties,
I right click my virtual directory and clicked the properties



1)in the Virtual Directory tab,
A)I set the Local Path to
  C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store
B) I checked the Read permision
C) Clicked the create button to create the application
D) Set Execute Permissions to Schipts only

2)In the Document tab, I added my ASP Default page and move it up


3)In the ASP.NET tab, I set ASP.NET version to 2.0.50727
0
 
SteveH_UKCommented:
Whoops!  Didn't check the last bit:

>After setting the Default Web Site properties,
>I right click my virtual directory and clicked the properties
>1)in the Virtual Directory tab,
>A)I set the Local Path to
>  C:\Documents and Settings\user\My Documents\Visual Studio 205\WebSites\Computer Store
>B) I checked the Read permision
>C) Clicked the create button to create the application
>D) Set Execute Permissions to Schipts only
>2)In the Document tab, I added my ASP Default page and move it up
>3)In the ASP.NET tab, I set ASP.NET version to 2.0.50727

This looks okay.  Make sure the ASPNET user has access to this folder.
0
 
SteveH_UKCommented:
>c:\Inetpub\Adminscripts>cscript metaacl.vbs IIS://LOCALHOST/W3SVC >mydomain\mydomainaccount RW
>
>RW will give the read and write permissions to mydomain\mydomainaccount.

I recommend you follow the instructions here: http://support.microsoft.com/kb/555583
0
 
vielkacarolina1239Author Commented:
I have the website runing in IIS when I click browse.

Howerver, I still get the same error when I try to run the application from Visual Studio.

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.C:\Documents and Settings\user\My Documents\Visual Studio 2005\WebSites\Computer Store\web.config      33      

Do I need to tell Visual Studio to use IIS and not the development server?

0
 
vielkacarolina1239Author Commented:

Do I need to create a web.config file for the subdirectories?

Thanks
0
 
vielkacarolina1239Author Commented:
I found the error. I was using
<location path="CatalogAdmin.aspx">
and this was generating the error. I replace this piece of code by

<location path="CatalogAdmin">

and the whole think works.


0
 
vielkacarolina1239Author Commented:
thanks, you helpped alot
0
 
SteveH_UKCommented:
Sorry for not getting back sooner.  You have the correct configuration, now.

You can use web.config files in subdirectories, but not all options are supported.  <location> elements are not supported in subdirectories that are not application starting points.

Thanks for the points :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now