web.config in nested folder - asp.net

I am trying to install an app inside of another web app. I have my .aspx pages and some code that I was putting into the main app's app_code folder. I've added my own web.config file for my connection string and such but I think there's a conflict. So my question is a two parter. First, what is the best way to install an app inside of another app, i.e should I use the main apps app_code folder or add my own, and second, would there be a conflict with the two web.config files. I was under the impression that the files pulled from the most specific web.config file. It appears there is a problem with my security and I am unable to access my file. I was attributing this to the two web.config files,
thanks.

If the nested application has had its folder turned into an application (right-click on it in IIS, Properties, and on the "Application" tab, "Create" a new application), you should put the code in the local App_Code folder:
- \RootFolder // Root of website
|- \App_Code // App_Code at root
|- \NewApplication // Seperate application in IIS, has "web in a box" icon in IIS
| |- \App_Code // App_Code of new application
If the nested application isn't a true application (in the IIS sense), then you will need to have the code files in the root App_Code folder.
This also has a bearing on your web.config - if the nested application is a true application, then you'll be able to have a full web.config at the level you want - however if it's not an IIS application, then there are limitations as to what you are able to put in subsequent web.configs - some elements are only allowed in the web.config at the application root, and can't be overridden by other settings.
What's the actual error you are seeing?

Regarding your first question, I would rather have them deployed on different folder. And second, if you have, for instance, a web site inside the default web site, you will have both web.config, but the more specific will override some of the attributes of the web.config from the default web site, but the ones that are not override will be there, (ie, HTTPHandlers, HTTPModules, the site will try to load those, so you will need to add the remove tag inside the HttpModules to remove them).
Hope this clarify your question

Related

web.config application pool error after moving to new server

I have the following error after move my website from server to another server
I have already checked iis and make sure the app has an application pool and it points to the correct file path
here is a screenshot of my application pool
I even tried to add virtual directory and add application and still not working
Check siteMapFile attribute of sitemap
The possible reason behind the issue is:
When you create a new web application using visual studio.net, it automatically creates the virtual directory and configures it as an application. However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and may get the above error. The debug information you get as mentioned above, is applicable to this scenario. To resolve it, Right Click on the virtual directory - select properties and then click on "Create" next to the "Application" Label and the textbox. It will automatically create the "application" using the virtual directory's name. Now the application can be accessed.
When you have sub-directories in your application, you can have a web.config file for the sub-directory. However, there are certain properties that cannot be set in the web.config of the sub-directory such as authentication, session state (you may see that the error message shows the line number where the authentication or session-state is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application (as mentioned in the above point). Mostly we have the practice of adding web.config in the sub-directory if we want to protect access to the sub-directory files (say, the directory is admin and we wish to protect the admin pages from unauthorized users). But actually, this can be achieved in the web.config at the application's root level itself, by specifying the location path tags and authorization.
in your case the site map section causing the issue. try to remove it from the config file.
You could refer this below link:
Nested ASP.NET 'application' within IIS inheriting parent config values?

Is there a way to tell a View in ASP.NET where to look for a Web.Config?

I've recently began a new project and I've decided to try to arrange the folders in a basic ASP.NET MVC project by feature (i.e. one folder would contain all Account files Models, View and Controller and another folder would contain Home Model, View and Controller etc...) instead of the default ASP.NET template. With this being said I quickly realized when I moved my views my controller was looking under the views folder. I fixed that but then my views were looking for the Web.Config and I fixed that by copying the views folder Web.Config into that folder. This is a solution but I want to know if I can point all my views to one Web.Config without having to have them all in the same folder.
Every folder in ASP.NET web application / website can have its own web.config file. Having said that, it is also necessary that the root folder of your application must have a web.config file based on which the application / website will be configured in the hosting environment.
Therefore, if you want to use different settings for different folders, you can place a separate web.config file with settings specific to folder in the any of the application folder.

Serve root application instead of subfolder

At work we have an ASP.NET MVC application with a 'Notifications' namespace and accompanying folder.
The problem comes when trying to access /notifications - IIS it tries to serve files out of the notifications folder, instead of invoking the site's default application.
This is not a problem when deploying because the code folders aren't deployed, but during development, IIS sees the folder and tries to serve it.
Does anybody know how to make it just serve the default ASP.NET application for the folder? The closest I got was setting up a virtual folder, but that doesn't work because of the web.config inheritance behavior.
I'm afraid the only way to fix this is to rename either your folder or your controller. They can't be the same name because IIS looks inside of the folder first, and then if the folder does not exist, it goes to the ASP.NET ISAPI which then routes it to your controller.
Reference: http://forums.asp.net/t/1781586.aspx?+Help+Controller+not+getting+hit
Sorry :(

Web.Config Issues

I have an ASP.NET web application that has a web.config file in the website's parent directory. I have another folder in the website which has another asp.net application. The folder also has a web.config directory for itself. When I run the application within the sub folder, it throws error and somehow these errors are related to references in root level application.
Initially it threw this error: code sub directory doesnt exist, . I added a dummy folder for this within the application in the sub folder but it seems to be looking for more references. is there a way to resolve this issue.
Parent application has it's own config and the application within Sub folder has it's own web.config. Whe i run the appl within sub folder, it is trying to use the web.config from parent application not it's own.
Thanks
Jay
you must clarify this:
I have an ASP.NET web application that has a web.config file in the
website's parent directory. I have another folder in the website which
has another asp.net application. The folder also has a web.config
directory for itself.
are you telling us you installed a web app and its web.config is not in the same folder but in a parent folder? This is wrong!
your other folder contains an asp.net application which has a web.config directory!?!?
in ASP.NET for nested or not nested applications you should basically have the web.config in the same folder where you have the default.aspx page and the bin sub-folder, if the web.config is not there but in any parent or child folder, it won't work, most likely.
I am assuming things here as you do not explain much, edit the question with more details and I will edit this answer :)

Multiple Global.asax files per web application project

I have existing web application project in which i need to add new subdirectory. In this subdirectory i need to add WCF service.
Question is: Can i use different AppDomain then services from root directory? Also, can i add new global.asax just for this subdirectory?
There's nothing in your question that wont stop you from defining the subdirectory as a new web application within IIS, thus allowing you to create new global.asax/web.config. Just remember that the web.config configuration is inherited by default, and you'll need to remove any handlers that your parent site added, but your subsite does not have.
When you are in the situation that the global.asax file has to be different then you are almost always better off splitting the service out to it's own project and deployment location.
This way changes in the main site won't impact the web service.

Resources