开发者

Is there a better way to get the proper modules section from the web.config?

开发者 https://www.devze.com 2023-02-05 08:51 出处:网络
The code I\'ve used to get the HTTP Modules is basically HttpModulesSection modules = ((SystemWebSectionGroup)config.GetSectionGroup(\"system.web\")).HttpModules;

The code I've used to get the HTTP Modules is basically

HttpModulesSection modules = ((SystemWebSectionGroup)config.GetSectionGroup("system.web")).HttpModules;
// Depending on what we need to do...
//modules.Modules.A开发者_如何学Godd(CreateSomeModule());
//modules.Modules.Remove("SomeOtherModule");

This worked fine up until IIS7. The migration command %SystemRoot%\system32\inetsrv\appcmd migrate config "website/" moves the modules into system.webServer, so my code is now updating the wrong section.

Is there a built in way to get the proper module section that should be modified? Or do I have to add a check for the Request.ServerVariables["SERVER_SOFTWARE"] and return system.web/system.webServer depending on the string I get back?


HttpContext.Current.ApplicationInstance.Modules

this returns a HttpModuleCollection object. Or do you want to know how to programmatically register HttpModules at runtime?

0

精彩评论

暂无评论...
验证码 换一张
取 消