2011-03-14 2 views
1

Web.config 대신 Azure ServiceConfiguration 파일에서 IIS 다시 쓰기 규칙을 읽을 수 있습니까?Azure ServiceConfiguration 파일에서 IIS 다시 쓰기 규칙을 읽을 수 있습니까?

발생하는 문제는 매주 새로운 URL이 생성되도록 관리되는 콘텐츠 인 매주 업데이트 된 페이지에 대한 우호적 인 URL을 가지고 있다는 것입니다. 이전 기록은 뉴스리스트 보관소에 저장되므로 덮어 쓰기는 옵션이 아닙니다.

매주 Azure 사이트 파일을 업로드하지 않아도되고 serviceconfig의 값을 변경하여 링크 변경 사항에 즉각적으로 응답 할 수 있기를 원합니다.

가능하면 누구나 다른 해결책이 있습니까?

감사

답변

1

예, 당신은 IIS 관리 API의 구성 편집기 클래스를 사용하여 런타임시의 web.config를 수정하는 역할을 변경할 수 있습니다. 나는 이것을 시도하지는 않았지만, 시작할 때 Azure 설정에서 설정을로드 한 다음 역할의 런타임 인스턴스에 적용 할 수 있어야합니다. 따라서 웹 역할의 global.asax의 Application_start 섹션에서이를 설정할 수 있습니다.

또는 시작 작업을 사용하여 역할 시작 시간에 web.config를 프로그래밍 방식으로 빌드 할 수 있습니다.

이 IIS의 포럼 게시물 iis.net에서 몇 가지 조사를 수행 한 후 읽기 : 1 방식의 경우

http://forums.iis.net/t/1150481.aspx

사용자 ruslany에서 샘플을 채취을 (여기서 인해 신용을 제공하지만, 그래서 붙여 넣기 그것을보십시오) :

using(ServerManager serverManager = new ServerManager()) { 
      Configuration config = serverManager.GetWebConfiguration("Default Web Site"); 

      ConfigurationSection rulesSection = config.GetSection("system.webServer/rewrite/rules"); 

      ConfigurationElementCollection rulesCollection = rulesSection.GetCollection(); 

      ConfigurationElement ruleElement = rulesCollection.CreateElement("rule"); 
      ruleElement["name"] = @"MyTestRule"; 
      ruleElement["stopProcessing"] = true; 

      ConfigurationElement matchElement = ruleElement.GetChildElement("match"); 
      matchElement["url"] = @"foo\.asp"; 

      ConfigurationElement conditionsElement = ruleElement.GetChildElement("conditions"); 

      ConfigurationElementCollection conditionsCollection = conditionsElement.GetCollection(); 

      ConfigurationElement addElement = conditionsCollection.CreateElement("add"); 
      addElement["input"] = @"{HTTP_HOST}"; 
      addElement["pattern"] = @"www\.foo\.com"; 
      conditionsCollection.Add(addElement); 

      ConfigurationElement actionElement = ruleElement.GetChildElement("action"); 
      actionElement["type"] = @"Rewrite"; 
      actionElement["url"] = @"bar.asp"; 
      rulesCollection.Add(ruleElement); 

      serverManager.CommitChanges(); 
     } 
관련 문제