Asp.net HttpModule in directory level web.config

后端 未结 4 1016
心在旅途
心在旅途 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条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 11:04

    Base HttpModule for this case could be the following:

    public abstract class PathBasedHttpModule : IHttpModule
    {
        public abstract void Init(HttpApplication context);
    
        protected EventHandler BuildConditionalEventHandler(Action targetHandler)
        {
            EventHandler action = (sender, args) =>
            {
                var settingsValue = CloudConfigurationManager.GetSetting(ModuleEnabledAppSettings);
                if (!string.IsNullOrEmpty(settingsValue) && bool.Parse(settingsValue))
                {
                    targetHandler(sender, args);
                }
            };
            return action;
        }
    
        protected abstract string ModuleEnabledAppSettings
        {
            get;
        }
    
        public void Dispose()
        {
        }
    }
    

提交回复
热议问题