web.config looks like this:
<system.web> <httpModules> <add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/> </httpModules> </system.web> <system.webServer> <modules> <remove name="DotNetCasClient"/> <add name="DotNetCasClient" type="DotNetCasClient.CasAuthenticationModule,DotNetCasClient"/> </modules> </system.webServer>
In C # code:
[assembly: PreApplicationStartMethod(typeof(CasClientStart), "Start")] namespace Dev.CasClient { public static class CasClientStart {
how to read httpmodule from web.config? Before the dynamic register module, I want to check Web.confg first.
my decision,
// the Final Solution public static void Start() { var IWantReg = typeof(CasClientModule).FullName; var Configuration = WebConfigurationManager.OpenWebConfiguration("~"); if (HttpRuntime.UsingIntegratedPipeline) { var websermodules = Configuration.GetSection("system.webServer"); var xml = websermodules.SectionInformation.GetRawXml(); XDocument xmlFile = XDocument.Load(new StringReader(xml)); IEnumerable<XElement> query = from c in xmlFile.Descendants("modules").Descendants("add") select c; foreach (XElement band in query) { var attr = band.Attribute("type"); var strType = attr.Value.Split(',').First(); if (strType.ToLower() == IWantReg.ToLower()) return; } } else { object o = Configuration.GetSection("system.web/httpModules"); HttpModulesSection section = o as HttpModulesSection; var models = section.Modules; foreach (HttpModuleAction model in models) { if (model.Type.Split(',').First() == IWantReg) return; } } DynamicModuleUtility.RegisterModule(typeof(CasClientModule)); }
终于 解决 了 这个 问题, 分别 通过 集成 与 经典 格式 两种 方式. 感谢 朋友 们 的 帮助.
source share