How do I make web.config apply to the root folder only? - iis-7

Is there a way of preventing inheritance of the web.config file in the root of wwwroot within IIS7 to all other sub-folders?
A developer installed a web app which put files in the wwwroot folder. All worked fine until Exchange 2010 was installed and didn't work. Removing the web.config file in the root of wwwroot gets Exchange working (OWA etc) but breaks the web app. Putting the web.config file back fixes the web app but breaks Exchange again.

To prevent inherited configuration to child applications, you wrap the <system.web> tag in a <location> tag, with inheritInChildApplications="false".
<location path="." inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>

Related

IIS Subsite with different web.config, Is it possible?

My IIS subsite take the web.config from the main site. How to avoid it?
I want my subsite just read its own web.config and works as independent site
This is how it looks in IIS:
img1
Yes, web.config contains the server configuration information related to each web application, there should be a web.config in the root folder of your web application.
If you want different web.config for subsite, you can place web.config file under your subsite of application.
<location path="." inheritInChildApplications="false">
<system.web> 
...
</system.web>
</location>

I want to url redired in asp.net using web.config

I have one or more than one url like http://vfiresolution.in/pdf/p.pdf. And I want to redirect the above url to http://vfiresolution.in/page.aspx?id=1.
I am using the below given code. My code is working on local host. But If i publish my code on shared server code not working.
my code is
<configuration>
<location path="pdf/p.pdf">
<system.webServer>
<httpRedirect enabled="true" destination="http://vfiresolution.in/page.aspx?id=1" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
http://www.iis.net/configreference/system.webserver/httpredirect
check the iis
(httpredirect)
Compatibility
The httpRedirect section of web.config is compatible with IIS 7 (w2k8) and IIS 7.5 (w2k8 r2).
Web.config files are deeply integrated with IIS 7.x.
The httpRedirect directives listed will apply to all files and directories (php, jpg, png, htm, etc), not just asp.net files.
While some web.config sections sometimes require that the containing directory is set as an application, this isn't one of them.
A simple web.config with a httpRedirect section may be placed in any directory, and the directory does NOT need to be set as an application.

ASP.NET 4.0 CSS in a folder is not cached

I converted an existing website from ASP.NET 2.0 to ASP.NET 4.0.
Now when I see the network tab in Firebug I see the css files in my root/css folder are retrieved upon each request with 200 OK response. So they are not cached.
Although the css files I have in my aspnet Theme are getting cached. So I moved the /css folder files in Themes folder and those files are now cached.
Why are styles in folder other than Themes aren't cached? I wonder if I am missing some configuration setting?
P.S.: I am running the new website from VS2010/DevServer/FireFox.
The reason the files in css folder were retrieved on every request was because my website required login and has anonymous access denied.
In my web.config I had explicitly allowed all users to App_Themes folder and that is why it seemed to be cached. So I added the following to my web.config and no more additional request for those files.
<location path="css">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Those css files weren't used on the home login page so never occurred it could be the access issue.

Prevent Visual Studio Dev server, IIS Express and full IIS from processing static files

Using Visual Studio 2010 I put a breakpoint on Application_AuthenticateRequest today and noticed that requests for my images, css and js were being processed. I switched my web application project to use IIS Express and then full IIS, and my breakpoint was still hit on those static files
I was under the impression that full IIS at the very least would by default not serve those files through the ASP.NET pipeline. What am I missing here??
You need to ensure that IIS is setup to serve static content.
See here.
I ended up adding this to my web.config. I know all my static files will exist in these folders, so it works ok for my needs.
<location path="scripts, styles, images">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
I'd suggest putting your static files on a separate subdomain and use AWS S3

IIS7: disabling HttpModule in subapplication - sites, application and virtual directories

I have a few aspx files in a "Cache" folder in my application and I do not want HttpModules to run for those files in that folder. I tried having a web.config in subdirectory but learned that HttpModules take the root web.config and not that of the subdirectory.
Reference 1, Reference2. So I decided to have this directory as a sub application as per suggestion here and here.
So I configure my application,then "add application" , map it to this directory, which already was inside this application and boom, it fails. It works for a static html file, but aspx files are not available.
My question is, how do I configure a sub-application in IIS7 so that the sub-application can have its own web.config and there I can disable HTTPModules of the root application
Edit:In fact I tried creating a subapplication within my main application and it did not work. Can some one point me to any article on how to configure a sub-application in IIS7 ?
Edit2: adding the error image. So how should I configure the child app pool. The child app runs in the same app pool as that of parent
Edit3: sorry, the child was running on a different app pool. A generic app worked(without modules). I am marking the answer after I try out the modules.Thanks for your help guys. There is something specific in my parent app web.config, which I am going to hunt down now.
EDIT: Actually both the answers provided below are correct. If you are using IIS7 integrated mode your modules should be in system.webServer and if IIS7 - classic mode your modules (and handlers?) should be in system.web
JKG has the right answer for IIS6, but the syntax is a little different in IIS7:
<system.webServer>
<modules>
<remove name="MyModule"/>
</modules>
</system.webServer>
The web.config will always inherit from its parent if it's in the same web application but you can clear the entire thing or remove an item like so:
From the child web.config (clear all or remove an item)
<httpModules>
<clear />
<remove name="MyModule"/>
</httpModules>
From the parent config by using the location tag...
<location inheritInChildApplications="false">
<system.web>
<!-- ... -->
</system.web>
</location>
http://www.jaylee.org/post/2008/03/Prevent-ASPNET-webconfig-inheritance-and-inheritInChildApplications-attribute.aspx

Resources