Asp.net HttpModule in directory level web.config

后端 未结 4 1078
心在旅途
心在旅途 2021-02-04 10:31

I created a custom http module and want to add this module to the web config. The web application is a project that contains several \"sub applications\". A sub application is j

4条回答
  •  Happy的楠姐
    2021-02-04 10:46

    To echo Marvin Smit's comment, it seems that configuring under a in web.config simply does not work - any modules specified in this fashion are NOT invoked.

    What you can do is to specify the module at root level, and have it controlled by an appSetting, which can be hierarchically specified and overridden as required:

    
    
    
      
        
      
    
    
      
        
          
        
        
          
            
          
        
      
    
      
        
          
        
      
    
    
    

    Then within the code for CustomModule:

        private static bool ModuleEnabled()
        {
            bool appSetting;
            if (!bool.TryParse(ConfigurationManager.AppSettings["UseCustomModule"], 
                               out appSetting))
                appSetting = false;
    
            return appSetting;
        }
    

    ASP.NET will see to it that the appropriate value of UseCustomModule for our current location is the one we read.

提交回复
热议问题