2016-11-29 15 views
1

나는C#에서 IIS 서버의 모든 웹 사이트에 대해 ApplicationHost.config에 HttpModule을 추가하려면 어떻게합니까?

public string[] RegisterInApplicationConfig() 
    { 
     using (ServerManager serverManager = new ServerManager()) 
     { 
      Configuration config = serverManager.GetApplicationHostConfiguration(); 
      var section = config.GetSection("location/system.webServer/modules"); 

     } 
    } 

같은 것을하려하지만 점점 오전 오류입니다 -

이 섹션 선언이 없기 때문에 섹션 location/system.webServer/modules가 읽을 수없는 구성.

How do I register a HttpModule in the machine.config for IIS 7?

그래서 기본적으로 ApplicationHostConfig에서 나는 어떤 & 시험을 친 후 그래서 나는 해결책을 발견

<location path="" overrideMode="Allow"> 
    <system.webServer> 

    <modules> 
     <add name="IsapiFilterModule" lockItem="true" /> 

답변

1

에 도착해야합니다 -

나는 HttpModule을 추가하는의 게시물을 참조하고있다. future-

에서 사람을 도움이 될 나는 "system.webServer/modules"섹션에 GetCollection을 할 필요가

Configuration config = serverManager.GetApplicationHostConfiguration(); 
      var section = config.GetSection("system.webServer/modules", ""); 
      var collection = section.GetCollection(); 
      var element = collection.CreateElement(); 
      element.Attributes["name"].Value = "MyHttpModule"; 
      element.Attributes["type"].Value = MyHttpModule.XXXModule, MyHttpModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bc88fbd2dc8888795"; 
      collection.Add(element); 
      serverManager.CommitChanges();