Connect Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 7 June 2012

How to disable web.config Inheritance for Child Applications in sub folders in ASP.NET?

Posted on 07:44 by Unknown
Each ASP.NET Web Application has its own configuration file called web.config file. 
In fact every directory in ASP.NET application can have one. Settings in each web.config file apply to the pages in the directory where its placed, and all the subdirectories of that directory.

This is called Configuration Inheritance. 


So if you create an ASP.NET application and set its web.config file, add custom HttpHandlers, UrlRewriting module etc and try to create another ASP.NET Web Application in the subfolder, you can end up having problems because application in the subfolder will inherit all the settings from its parent  web.config.


So if you for example setup UrlRewriter module in your root web applications like this:


       <httpModules>
             <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
                <add name ="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>

And in your child web application (in subfolder) you are not using UrlRewriteModule, then if you try to run the child Web Application in your browser, you will get error like this:




Configuration Error:


Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 


Parser Error Message: Could not load file or assembly 'UrlRewritingNet.UrlRewriter' or one of its dependencies. The system cannot find the file specified. (d:\Projects\VS\AspDotNetFaqProject\Website\web.config line 89)


Source Error: 


Line 88: <httpModules>
Line 89: <add name="UrlRewriteModule" type="UrlRewritingNet.Web.
              UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
Line 90: <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
             System.Web.Extensions, Version=3.5.0.0, Culture=neutral,  
             PublicKeyToken=31BF3856AD364E35"/>
Line 91: </httpModules>

What happens here is that because UrlRewriteModule is configured in the parent's folder web.config file, this setting is inherited by the child application's web.config file, and because of this ASP.NET is looking for the UrlRewriteModule DLL file in the BIN directory, and off course its not there.


Luckily, there is a easy solution to this problem.


First thing you can do is to remove the problematic HttpModule in your child application web.config file using the remove command like this:


      <httpModules>
        <remove name="UrlRewriteModule" />
      </httpModules>

This would remove the handler and your application would run fine.
Or you could use <clear/> command like this:


       <httpModules>
            <clear/>
       </httpModules>

This would clear all the HttpModules in your child application.


But what to do when there are many settings in your root web.config file that you don't want to be propagated to your child applications?


Here is the solution:
With the <location> attribute with inheritInChildApplications  set to false  in your root web.config file you can restrict configuration inheritance. 
So, by wrapping a section of your web.config file in <location> attribute you can instruct ASP.NET not to inherit those settings to child applications/folders and their web.config files.


In fact  you can wrap the whole <system.web> section in one <location> attribute and disable configuration inheritance so none of the parent settings from <system.web> will be inherited to the child applications you create in subfolders.


Here is how to use this in practice:


 <location path="." inheritInChildApplications="false">
    <system.web>
    ...
    </system.web>
  </location>
  
NOTE: Do remember that if you do this, you need to manually insert all the settings you need in the <system.web> for your child applications because none of the settings from the root web.config will be propagated...
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • How to schedule a PHP script in task scheduler
    Quiet often there is a need to execute/run  php  script on some time interval at server side. And that php scripts should run automatically ...
  • HTTP Error 403.19 – Forbidden The configured user for this application pool does not have sufficient privileges to run CGI applications.
    If you get the error “HTTP Error 403.19 – Forbidden The configured user for this application pool does not have sufficient privileges to...
  • Roles and Features showing an error HRESULT: 0x800F0818 in Server Manager of windows server 2008 R2
    When you open Server Manager both Roles and Features display Error and you are unable to add any role or features. When you select the det...
  • How to resolve Windows Login Error: "An unauthorized change was made to Windows"
    After connecting to windows server via RDC, you receive error “ An unauthorized change was made to Windows ” Resolution: 1) Click the opt...
  • How to configure IIS 7 to redirect non-www domain to www domain?
    One of few legacy leftovers that was never dropped over the years is the common use of www domain prefix. It is not a problem per se for us...
  • Reset Mysql root Password using my.ini
    Follow the below given steps to reset the Mysql root password : 1.Browse to your MySQL installation directory. 2. In there, go to "Data...
  • Disallowed Parent Path
    If you are unable to access the website and facing the below error: Active Server Pages error 'ASP 0131' Disallowed Parent Path /adm...
  • How to upgrade Zen Cart 1.3.9 to Zen Cart 1.5
    To upgrade your Zen Cart 1.3.9 to Zen Cart 1.5, follow the following steps. (For this tutorial, I assume you are using cpanel web hosting) 1...
  • Block IP from accessing website using .htaccess
    Block IP from accessing website using .htaccess To block certain ip address from accessing your website, just create a file with name .hta...
  • Enable Canonical URL in IIS7 for SEO
    What is URL Canonicalization?  – Its just nothing but you are making sure that your users and the search engines are accessing your websites...

Categories

  • booting Process
  • linux
  • redhat

Blog Archive

  • ►  2013 (68)
    • ►  July (1)
    • ►  May (2)
    • ►  April (11)
    • ►  March (54)
  • ▼  2012 (44)
    • ►  September (20)
    • ►  August (1)
    • ►  July (4)
    • ▼  June (12)
      • Enable Canonical URL in IIS7 for SEO
      • How to disable web.config Inheritance for Child Ap...
      • New in IIS 7 - App Pool Isolation
      • Application Pool Identities
      • Ensure Security Isolation for Web Sites
      • Getting Started with AppCmd.exe
      • Introduction to ApplicationHost.config
      • How to Capture ASP.NET Page Trace Events in IIS 7....
      • Installing and Configuring Web Deploy
      • Classic ASP parent paths are disabled by default
      • Classic ASP Script Error Messages No Longer Shown ...
      • Classic ASP Not Installed by Default on IIS 7.0 an...
    • ►  May (2)
    • ►  March (4)
    • ►  February (1)
  • ►  2011 (1)
    • ►  February (1)
  • ►  2009 (9)
    • ►  September (3)
    • ►  August (2)
    • ►  June (1)
    • ►  May (2)
    • ►  March (1)
Powered by Blogger.

About Me

Unknown
View my complete profile