Errors after add Virtual Directory in IIS - asp.net

My web service on IIS can work well w/o a virtual directory (called by http://localhost). However, I want to call it like http://localhost/virtualpath.
So I added a virtual directory in IIS, but when I explorer website, it gives me the following error:
What does this mean and how to solve it? (I'm using IIS 8.5)

It means exactly what the error says - you've tried to set a section in web config beyond application level. I'm assuming that you added the virtual directory under a pre existing website in IIS? What you want is to add a physical directory under the website with your app in and then simply right click and convert that folder to an application.

Related

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.

The requested page cannot be accessed because the related configuration data for the page is invalid

I am getting this error when I try to run an ASP.NET application without a web.config file.
The requested page cannot be accessed because the related configuration data for the page is invalid
as I read, we can run .NET applications without web config files, but when I tried it is giving me the error. I am using iis 7 on windows 7 machine.
When I create the application virtual directory inside inetpub/wwwroot it works fine. Why doesn't the other directory location?
One reason could be the version of .NET framework (on IIS or application pool level) is different from the application one.
Another reason could be if there are modules used in your web.config which the current configuration of IIS doesn't recognize. E.g. URL rewrite or other optional modules, which you have to explicitly enable before using.
This can be a reason:
If there is no Web.config file in the
UNC directory, IIS 7.0 uses the rules
that are defined for the parent
directory. For the Web content to be
served in this scenario, the
worker-process identity must have
access to the whole content directory.
Otherwise, the Web request is
rejected.
Details here.
You need to set permission for your Website folder or copy them to wwwroot folder.
If you choose to set permission, there are two ways:
Right click on Your Website folder, or
Right click to Your Website in IIS
Then select Edit permission and Add a permission (IUSR - default iis user)

Nested virtual directory or application within sitecore site, is it possible

I would like to nest asp.net web app within sitecore site, something like this:
<sitecore web root folder>
.
<virtual directory/app folder>
I want to access sitecore site by using following url:
http://<whatever site name>
and I would like to access web app by using following url:
http://<whatever site name>/<whatever virtual directory/app alias>
Is this possible?
I tried it but when I try to access my web app (not sitecore) then web app complains about missing sitecore.
I believe that is because now I have two config files ans when accessing web app iis/asp.net processing first sitecore web.config.
Right, your assumption is correct. See Creating a project in a virtual directory under Sitecore root article for more information about this kind of setup.
You should be able to create a virtual app under a Sitecore root path. Because its an app it will use its own app pool and you can have a web.config for it. I guess the physical files will be OUTSIDE of the Sitecore Website folder but the from a URL you can make the virtual app located anywhere below the Sitecore root.

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