asp.net 코드에서 웹 수정.config 노드의 구체적인 방법

1527 단어
그러나 이 변수는 고정된 값이 없고 실제 상황에 따라 변화가 발생한다. 예를 들어 프로필을 읽어야 하는 경로이고 이 경로는 사이트에서 발표한 실제 하드디스크 경로이다. 직접 컴파일할 때의 상태라면 문제가 없다.그러나 사이트 iis가 경로를 바꾸면 이 웹을 수정해야 합니다.config의 매개변수입니다.만약 이 컴파일링 시 상태를 실행 시 상태로 수정할 수 있다면 더욱 합리적이고 편리할 것이다.이것은 코드에서 웹을 동적으로 수정할 수 있는 것이 필요하다.config의 방안입니다.
코드
 
 
  
  ///
          /// web.config
          ///

          /// appSettings
          ///
          ///
          public void WriteConfig(string item, string key, string value)
          {
              if (item == "")
             {
                 item = "appSettings";
             }
             Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.HttpContext.Current.Request.ApplicationPath);
             AppSettingsSection appSection = (AppSettingsSection)config.GetSection(item);
             if (appSection.Settings[key] == null)
             {
                 appSection.Settings.Add(key, value);
                 config.Save();
             }
             else
             {
                 appSection.Settings.Remove(key);
                 appSection.Settings.Add(key, value);
                 config.Save();
            }
         }

좋은 웹페이지 즐겨찾기