web.config は次のようになります。
<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>
C# コードの場合:
[assembly: PreApplicationStartMethod(typeof(CasClientStart), "Start")]
namespace Dev.CasClient
{
public static class CasClientStart
{
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
if( !..... Registered (DotNetCasClient) In Web.config)
DynamicModuleUtility.RegisterModule(typeof(DotNetCasClient));
}
}
}
web.config から httpmodule を読み取るには? Dynamic Register モジュールの前に、まず Web.confg を確認したい。
私の解決策、
// 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));
}
この問題を解決するために、それぞれが 2 つの方法でサポートされています。