Web.config inheritance and virtual directories - asp.net

I have created a virtual directory and converted it to its own application and put it in it's own app pool and it's still inheriting settings from the root apps web.config file, it there anyway to stop this from occuring?

This is something that has caused me headaches for the past 18 years (since I work with .NET and IIS). This inheritance has never served any benefit but has caused numerous unexpected broken websites (you update the root and don't realize it breaks the child or you tested the child in an environment with a different root and when publishing it stops working).
So I decided today to search again and found something that works on a microsoft forum, but you need to change the parent not the child website. Put location tags around the system.web node of the web.config of the root website
<location inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>

Related

ASP.NET, two Web.Config

I have a .NET application with all the aspx pages and the main web.config in the root folder but I now have a situation where I need a portal like section for other users. I have created a new folder with it's own unique aspx pages and a second web.config.
I especially need a second web.config to have the <authentication> with a <forms loginUrl="" defaultUrl="> for this portal section and a <authentication> too.
I have implemeted this second web.config in the way I created the first and I am getting this error message:
It is an error to use a section registered as allowDefintion='MachineToApplication'
beyond application level. This error can be caused by a virtual directory not being
configured as an application in IIS.
Now I think the main web.config file is conflicting with the this second webconfig in it's folder. I'm not sure how to fix this, I have seen theories on how this works but no solid code.
Thank you for any suggestions and your time, it is much appreciated.
In IIS, create a virtual directory, under your main application. The local web.config will overide stuff in your main web.config, but still use you main web.config for everything else (i.e. ConnectionStrings, encoding, etc.).

IIS website paths behave different when accessing the site from outside the network

As the title states, I get different behavior on my website when I try to access it from the internet, as opposed to accessing it from the local network, and I cannot figure out why. I know it is because IIS is trying to serve me content from the parent application, but I don't know how to fix it.
Let me try explain: I have a website (not a web application) that I deployed to an existing IIS site, and then converted it to an application. If I access the website from the local network (<hostname>/path/to/site.aspx) then everything works fine, but when I try to access the site from the internet (<domain.name>/path/to/site.aspx) then it breaks, and I have the mappings set up correctly for the domain (it works on the parent application).
Initially it couldn't access the Site.Master page, saying the file cannot be found at <Site Parent Folder>/Site.Master (Instead of <Site Parent Folder>/<Current App>/Site.Master), so I had to change the master page reference on the ASP page from ~/Site.Master to just Site.Master And that seems to have worked for the master page only. It now gives me an error about being unable to find my classes in the App_Code directory (The type or namespace name 'MyClass' could not be found. Are you missing a using directive or an assembly reference?) so I'm suspecting that it is still trying to reference those from the parent directory.
Any ideas on how I can fix it so that it references the current application's directory instead of the parent app's directory?
Thanks in advance.
Ensure that your deployed website is running as a sub-applicaiton under main IIS site.
In your main IIS website update web.config and wrap system.web section with location element with inheritInChildApplications set to false
<location path="." inheritInChildApplications="false">
<system.web>
…
</system.web>
</location>
You can read more about it here

IIS Site Inheritance

I'm looking for advice on how to handle multiple web.configs in a single IIS site. I have little experience in IIS but need to figure this out.
Background:
1) We have an intranet application running on a single site in IIS 7.5
2) We have custom application code on various servers that we iframe into our intranet and want to piggy-back on our intranet's URL. (intranet.com/custom/blah.aspx)
3) To accomplish this we created virtual directories within our IIS intranet site. Unfortunately, this appears to cause some inheritance/conflict between our intranet's web.config and the web.configs for our various custom applications.
My initial thought is that perhaps we need to remove our custom applications from our IIS intranet site and create new IIS site, but I’m not sure if/how this would be possible as we still want to piggy back on the same URL.
Any ideas?
Let me know if additional detail/clarification is needed.
In my opinion you can still go ahead with your existing setup i.e. having custom applications as virtual directories in your intranet application.Its just you need to resolve conflicts in web.config. There are two ways to resolve those conflicts.
Tell your intranet application's web.config not to push its configurations on child directories. Way to achieve this is use location tag. e.g.
If you want parent app not to push its connection strings to children directories then use following construct.
<location path="." inheritInChildApplications="false">
<connectionStrings>
</connectionStrings>
</location>
If you wrap all those conflicting settings in location element then it will not get pushed to children directories. You have to be cautious here as it will stop inheritance to intranet application's own child directories and not just virtual directories.
Tell your custom application's web.config not to inherit configurations from parent directories. Way to achieve this is use <clear/> element.
In your custom application's web.config for all those conflicting settings you first clear settings coming from parent and then add specific settings you want to add. e.g.
<connectionStrings>
<clear />
<add your specific connection string>
<connectionStrings>

Add Standalone ASP.Net Application Into Existing ASP.Net Website - not working

I have an asp.net '4.5' site (Orion Solarwinds) and I would like to add functionality. This can be done with a virtual directory, but adding anything to that folder will cause a recompile and interrupt service to the user.
It should be possible(and done it many times before) to 'just' add a application. So I should be able to use a separate application pool.
BUT what happens is that even with a index.html file in an empty application with a web.config in there, it still seems to inherit from the host webconfig. Thus this is not a Standalone ASP.Net Application in an existing website. I have tried to decouple this basic application - no joy. How can I fix this?
You can try using inheritInChildApplication by wrapping sections you don't want to inherit in host webconfig with this:
<location path="." inheritInChildApplications="false">
There's more details in this other thread

Same website different port Javascript and Stylesheets

I've a website running under IIS7. Everything works fine with this website. I've copied the directory and created a clone website on a different port. When I browse to the new website on the different port, I do not get any of the style settings until I log in -- then all appears normally.
The problem appears to do with the ASP.NET Membership/Authorization. I have a web.config in the subdirectories to allow all users (web.config) but the clone website is not using them even though all the config, directories, etc are the same. Only the port is different or non .config settings that IIS 7 uses.
I've discovered the problem but not the whole answer. The directories needed the IUSR permission to work but the original website doesn't have those permissions. It only had IIS_IUSRS. IF anyone can fully explain this behavior and how to fix the problem without granting IUSR then I will award the bounty for that answer.
The answer should be fully explanatory.
One potential issue would be with authorization settings in your config.
Look for something like this:
<location path="MyResourcesFolder">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
The above example would produce the effect that you've described assuming that your resources (css, jscript, etc) were located in a folder named MyResourcesFolder. Check the web.config that's in the actual website and not necessarily the project. This is because your website config may not be the same as your project config if you are using config transformations.

Resources