ASP.Net - It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level - asp.net

Getting this error on an intranet application we have running in our development environment, and I'm not sure where to go/look for a solution. The application used to work fine, however it is run on a shared server with another team of developers and we're having trouble tracking down the error (no updates were made to the application by my team, it suddenly stopped working).
We're running Windows Server 2003 and IIS 6.0. If I open the solution on my machine, however, I receive an error in Visual Studio solution points to this line in the web.config, however I believe this is a relatively standard setting and we actually have this running in another environment (same server/IIS set up)
<authentication mode="Windows" />
The error reads
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've also changed the <system.web> section of the web.config on the server to include <customErrors mode="Off"/>, however oddly enough when I navigate to the site I am still getting the custom error page...
I'm relatively new to IIS and never worked with Windows Server 2003. Can someone help point me in the right direction either to get the actual error so display in the browser or how to fix the error given to me by Visual Studio?

Bring up project properties page in Visual Studio. Right-click on project node in Solution Explorer and click properties. Look for the Web tab and click the button to create a virtual directory.

In some cases this could be caused by creating another sub-folder in your project and you added another Web.config file which has the same filename as the other Web.config file in the root folder.
To resolve this error, rename your newly added Web.config file to another name.

In my case inside my web directory, I had an other web directory along with its own web.config file. When I removed that sub directory that was a complete website in its own my problem is fixed now.

Just had this issue ... turned out to be a result of allowing debug information to be produced when publishing the Web App.
Publish Web App - Settings - File Publish Options - Precompile during publishing (true) - Configure - Emit debug information. (Should actually read "Omit debug information")
Delete Debug subdirectory of project and republish

This can also happen when you create a publish folderprofile if you take the default location, which is app.publish folder under your project folder. VS then gets confused and thinks there's another web.config it has to reconcile when building. Why does microsoft allow you to shoot yourself in the foot like this? Moving the Publish FolderProfile to another location stops the error from occuring.

any how web.config should be in the root directory most probably it happens when you don't have the solution file for your project. Close VS open it once again and choose the direct folder. Note web.config file should be in root directory or if you want to in sub directory then copy the webconfig file and create a new config file in the root. Caution:if you have mentioned any path in config file that will be lost

I had this problem. I think I caused it to start happening by modifying some settings in the publish profile. Undoing those settings fixed my issue. Here's what I did:
Right click on the project and go to publish
In the publish tab, in the configuration row, click "configure"
go to the settings tab
expand File Publish Options
I unchecked all of the options that were there. (checking some of these is what i believe caused my problem in the first place)
I deleted the bin and obj folders in my publish directory.
I have VS2017

Related

Start an ASP.net website from a specific folder using IIS Express via command line

I've written and ASP.net MVC web application that needs to be installed as a "normal" application (or as close to it as possible). By which I mean, I need to have a "double click on exe file and the webappp opens in default browser" behavior, or as close to that as possible.
Being used to Java, I stupidly thought that I could use and embedded webserver to run it, but after a bit of research (correct me if I'm wrong here) it seems this cannot be done (only ASP.net Core can do that, but I'm using the traditional .NET Framework) and the web app needs to be run in either IIS or IIS Express.
So, after more research, this page:
https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line
seems to suggest that launching a site from a specific folder via IIS Express is possible, by using a command like:
iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
where the path above contains my compiled ASP.net MVC website.
This, however, doesn't seem to work. When I issue that command I get the following output:
c:\Program Files\IIS Express>iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
Copied template config file 'c:\Program Files\IIS Express\AppServer\applicationhost.config' to 'C:\Users\MyUser\AppData\Local\Temp\iisexpress\applicationhost20179188941639.config'
Updated configuration file 'C:\Users\MyUser\AppData\Local\Temp\iisexpress\applicationhost20179188941639.config' with given cmd line info.
Starting IIS Express ...
Successfully registered URL "http://localhost:8080/" for site "Development Web Site" application "/"
Registration completed
IIS Express is running.
Enter 'Q' to stop IIS Express
So basically IIS Express starts, but it's not running my website from the folder I specified, it runs some (presumebly) default empty website, called "Development Web Site". I checked some urls, and I can confirm that is not my website, but just an empty shell with no pages or anything else.
What am I missing here? How do you start a website in IIS Express via command line? Do I have to "register" the website first somehow?
EDIT:
After a bit more research, I found out I can register a website explicitly by doing:
appcmd.exe add site /name:MySite /physicalPath:"C:\Program Files\MyWebsite\bin" /bindings:http://localhost:8081
and then start it with:
iisexpress.exe /site:MySite
This however doesn't solve the problem: when I browse to the website via browser all I get are 404 errors, there's no content at all.
One thing I also must point out: since an ASP.net website is compiled into a DLL file, I don't understand how simpy registering/starting it using a path to a FOLDER would work... how would IIS Express understand which DLL to load the site from? Seems like there are some crucial pieces missing here...
After further tinkering, I figured it out. I was pointing to the /bin directory of the website. Instead, you have to point to the parent directory, the one that contains the Web.config file.
So, in my case, I changed:
iisexpress.exe /path:"C:\Program Files\MyWebsite\bin"
to:
iisexpress.exe /path:"C:\Program Files\MyWebsite"
and now it works correctly

Asp.Net is looking for the web.config in the wrong place

I've got a strange issue - Up until now I've only worked on this application on a single machine. I've downloaded an asp.net web app onto a dev machine in a clients office.
When I try to run the application in debug mode through Visual Studio I get 500.19 error - typically this means a permission problem. I went through the motions of checking the permissions before I noticed the directory it was looking for the config file in.
The 'Config File' shown on the error is
\\?\C:\Users\{my-name}\Documents\{project-name}\web.config
however the correct location is actually
C:\Users\admin\Documents\projects\{project-name}\web.config
Does anyone know where the location of the web config is specified? I had always assumed it could only ever be in the root directory.
As it turns out the cause of this was upgrading to Visual Studio 2015.
Rather than a .suo file the new Visual Studio has a .vs folder with files specific to an instance of a project. The root directory of the development site is included in here.
I deleted the files and added .vs/* to my .gitignore file and had no more problems.
At our infrastructure it turned out that inside the web.config withing the node <system.webServer>, we had a nested node named <rewrite />. That one wasn't recognised by IIS.
By either removing that node or installing the missing feature (url-rewrite), the application started as expected.
In my case, the top level website in IIS had a physical path of:
C:\Users\MyUserName\Documents\My Web Sites
For some reason, this meant IIS refused to look anywhere else, even though my projects underneath had been converted to applications.
Fix for me:
Go to IIS
Right click on the top level website (i.e. 'Default Web Site', or the problematic website at the same level)
Select 'Manage Website > Advanced Settings'
Change the physical path to C:\inetpub\wwwroot
Save and reload website
I could then have any path for my applications and IIS could work it out as expected.
Assuming you mean Documents\projects\{project-name}\web.config instead of Documents\projects{project-name}\web.config you're seeing the effect of Application Scopes.
In IIS, multiple entirely separate web-applications can be part of the same website by being split-up into "Application Scopes" - which usually works by specifying a prefix path followed by the Scope root (prior to IIS7 an Application Scope could be a physical or virtual directory, since IIS7 they're always virtual directories, but can still represent a physical directory).
Open IIS Manager and select the (virtual )directory that Visual Studio created for your project and right-click it in the left-side Navigation pane and choose "Convert to Application", then ASP.NET will look for the web.config file (and the bin directory, amongst others) in this folder only, rather than the website root.
Note that the website root is also considered an application scope root, hence the common error message "Exception in "/" application". If you get a YSoD in another application root you'll see "Exception in "/subFolder" application" messages.

what is a root directory in IIS 6 and How do I make one of my subfolder in ASP.NET website the root directory?

I need to integrate a third party plugin in my asp.net website. To install the plugin, they have mentioned this sentence, "Create an application through your IIS control panel with root directory at -(some path from my website folder)?".
I am not much aware with IIS and rarely worked with it. Though I tried every possible way I could do in IIS, I am not able to work it out. After installation, there is a test page provided by plugin which I have to run to check but when I run it, it shows this 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 searched this error too and found that it is because the two Web.Config file, one from the main project and another from plugin folder. The only way to work with this, is to make the plugin folder they specified as a root directory in IIS. Someone kindly tell me some easy steps to do this.
What I was doing is, in IIS6, I added New website with the main folder of my asp.net website, then I right click>add application and choose the given path, thought it would become root directory but it is not.
Help would be appreciated. Also note that, I have to put the plugin folder in my main website folder only. So, there are two web.config. I tried to rename one of them too, it solved the above error but gave another errors but I think main problem is of root directory. P.S they show me above error on web.config file of plugin folder on this sentence-
"Line 51:
< authentication mode="Windows" />"
Most of the times the root directory is C:\inetpub\wwwroot folder and "Default Web Site" on IIS Manager.
Open IIS Manager and under Sites there should be IIS websites and under it you will probably see Default website. You can see the root directory with Right click/Settings.
Copy your website files under this root directory.
And after copying folder to root folder you will see this folder under Default websites on IIS.
Right click your directory name on IIS and "Create Application", select correct .net framework.
It should be work. Good luck, if you need more help please give more details on your server IIS.

ASP.NET What causes: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application...?

I have an ASP.NET web site. I keep getting the error below in VS 2008. The site works fine from a browser. I have made every folder using IIS manager an ASP.NET app. Why does it keep complaining? The site's folder is below a parent folder.
I am not familiar with web site apps instead of web application app. Where are the options to use IIS or the internal web server like WAP has?
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 dealed a lot with this error when having more than one web.config in the same virtual web directory / website. It may happen if you make a temporary backup of your website for example. Could you verify it?
This error can occur when you are you redefining stuff in the web.config of your virtual directory that you cannot override. Such as authentication or sessionstate. Try deleting all web.configs in your virtual directories to see if that solves the problem.
You likely have a virtual directory set up as a real site, having a bin directory, aspnet_client and web.config.
Either remove those and run it as a relative path, localhost\subdir\default.aspx, or create a new website in IIS to point directly at it.
My workaround was to move each folder into its own folder under wwwroot.
I resolved this issue by doing the following,
Select your project in Visual Studio and click 'Show all files' under Solution Explorer.
Delete the 'obj' folder and recompile.

MSBuild error while compiling ASP.NET website

I get the following error when I try to compile an asp.net site using a custom build script.
error ASPCONFIG: 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.
Although the description is in detail I do not understand what it means exactly. I have not configured IIS to host this website and I don't think I will be able to as I am running Vista Home Basic version. So the website cannot be built using custom scripts?Please reply as I want to test this feature.
I had this SAME EXACT problem and finally discovered a rogue Web.config was placed in my obj folder ... do yourself a favor and do a search in all the sub-directories for a web.config file. I deleted it and all was back to normal.
The rogue web.config file in the obj folder is most likely to be caused when you do a Publish Web Site. So just clean it up after you've done the publish.
if this happens after the virtual-directory is already created do the following:
right-click on web.config
properties
Build Action: Content
Copy to Output directory: Do not copy
if transformed (apply to all configurations)
properties
Build Action: None
Copy to Output directory: Do not copy
It is likely that your web.config file is placed in a directory that is not the root of the application. On most versions of IIS, you can convert any folder on your web site to an application root:
Open IIS and navigate to the appropriate folder
Right-click on the folder, select properties
Under Application Settings, and beside Application name, click Create
Apply and close
If this does not fix your problem, there may be another configuration error, either with IIS or your application.
In IIS, go to the folder that the app runs under, right click it, go to properties.
On the Directory tab, look for "Application settings". Click the create button.

Resources