[英]Is there a better way to get the proper modules section from the web.config?
The code I've used to get the HTTP Modules is basically 我用来获取HTTP模块的代码基本上就是这样
HttpModulesSection modules = ((SystemWebSectionGroup)config.GetSectionGroup("system.web")).HttpModules;
// Depending on what we need to do...
//modules.Modules.Add(CreateSomeModule());
//modules.Modules.Remove("SomeOtherModule");
This worked fine up until IIS7. 在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. 迁移命令%SystemRoot%\\system32\\inetsrv\\appcmd migrate config "website/"
将模块移动到system.webServer
,因此我的代码现在正在更新错误的部分。
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? 或者我是否必须添加对Request.ServerVariables [“SERVER_SOFTWARE”]的检查,并根据我收到的字符串返回system.web
/ system.webServer
?
HttpContext.Current.ApplicationInstance.Modules
this returns a HttpModuleCollection
object. 这将返回一个HttpModuleCollection
对象。 Or do you want to know how to programmatically register HttpModules at runtime ? 或者您想知道如何在运行时以编程方式注册HttpModules ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.