2012-12-03 2 views
0

하나의 web.config 파일에 두 개의 위치 요소가 있으며 코드의 권한을 변경하려고합니다.하나의 web.config에 여러 위치 요소의 권한 섹션을 코드 뒤에서 설정

의 Web.config 위치 섹션은 다음과 같습니다

<configuration> 
    <location path="~"> 
    <system.web> 
     <compilation debug="false" targetFramework="4.0"/> 
     <authorization> 
     <allow roles=""/> 
     <deny users="*"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="~/SubPage"> 
    <system.web> 
     <compilation debug="false" targetFramework="4.0"/> 
     <authorization> 
     <allow roles=""/> 
     <deny users="*"/> 
     </authorization> 
    </system.web> 
    </location> 
</configuration> 

코드에서 나는 위치 요소를 통해 이동하여 특정 위치의 요소에 변경을하고 싶습니다 뒤에. 예를 들어, 뒤에 C# 코드는 다음과 같습니다 내가 여기에 몇 가지 다른 일을 시도하지만, 실제로 지금까지 작동하는 하나 개의 솔루션이없는

Configuration myConfig = WebConfigurationManager.OpenWebConfiguration("~"); 
ConfigurationLocationCollection locations = myConfig.Locations; 
foreach (ConfigurationLocation location in locations) 
{ 
    if (location.Path = "~") 
    { 
    //define & clear the authorization section of the particular location element. 
    //create and apply rule for allow in that authorization section. 
    //create and apply rule for deny in that authorization section. 
    //save the change 

    } 

    if (location.Path = "~/SubPage") 
    { 
    //define & clear the authorization section of the particular location element. 
    //create and apply rule for allow in that authorization section. 
    //create and apply rule for deny in that authorization section. 
    //save the change 

    } 

} 

... 나는 웹에 어떤 변화를 consoldiate해야합니다. config를 루트 디렉토리 (~)에 추가하십시오 (모든 변경 사항은 서브 페이지의 다른 파일이 아닌이 파일에 반영되어야합니다). 블랭크를 채우기 위해 권장되는 작업 솔루션은 무엇입니까? 그 목적은 관리자 사용자가 내부 네트워크의 어떤 사용자 또는 Windows 그룹이 두 위치를 볼 수 있는지 결정하기 위해 관리자 사용자 인터페이스를 변경할 수 있도록 허용하므로 코드에서 허용 된 역할을 특히 변경하려고합니다. 감사합니다. .

답변

0

여러 번 시도한 후에 동일한 파일에서 모든 변경을 시도하지 않고 대신 각 위치에 새 구성 관리자 인스턴스를 열었습니다. 경로.

WebConfigurationManager.OpenWebConfiguration (location.Path) 그런 다음 각 위치의 개별 web.config에 규칙을 적용했습니다. 모든 권한 부여를 한 곳에서 중앙 집중화 할 수는 없었지만 적어도 작동 중이었습니다.

+0

아이디어 나 코드를 공유해 주시겠습니까? 사실, 지금 나와 같은 작업이 필요합니다. – Raghurocks

+0

http://go4answers.webhost4life.com/Example/programmatically-update-authorization-170136. aspx – fa1c0n3r

관련 문제