2012-10-01 3 views
0

문제점이 있습니다 (또는 적어도 생각한 것 같습니다). 나중에 사이트간에 폼 인증 데이터를 공유 할 준비를하기 위해 web.config에 사이트의 컴퓨터 키를 설정하려고합니다. 내가 처음의 Web.config에 다음과 같은 설정 :web.config의 machineKey가 예상대로 작동하지 않음을 나타냅니다.

var machineConfigMachineKey = (MachineKeySection)WebConfigurationManager.OpenMachineConfiguration().SectionGroups["system.web"].Sections["machineKey"]; 
var webConfigMachineKey = (MachineKeySection)WebConfigurationManager.OpenWebConfiguration("").SectionGroups["system.web"].Sections["machineKey"]; 
Response.Write("<pre>"); 
Response.Write("<b>machine.config decrypt: </b>" + machineConfigMachineKey.DecryptionKey + "<br />"); 
Response.Write("<b>web.config decrypt:  </b>" + webConfigMachineKey.DecryptionKey + "<br />"); 
Response.Write("<br />"); 
Response.Write("<b>machine.config validate: </b>" + machineConfigMachineKey.ValidationKey + "<br />"); 
Response.Write("<b>web.config validate:  </b>" + webConfigMachineKey.ValidationKey + "<br />"); 
Response.Write("</pre>"); 
Response.End(); 

...에서 어떤 결과 : 시험으로

<machineKey validationKey="<SOME_VALUE>" decryptionKey="<SOME_VALUE>" validation="SHA1" decryption="AES"/> 

을, 나는 Web.config의 새로운 machineKey 요소를 테스트하려면 다음을 썼다 이 디스플레이 : 내가 대신 "AutoGenerate를, IsolateApps"의 Web.config의에서 새로운 machineKey 요소에서 사용자 지정 값을 볼 것으로 예상되면서

machine.config decrypt: AutoGenerate,IsolateApps 
web.config decrypt:  AutoGenerate,IsolateApps 

machine.config validate: AutoGenerate,IsolateApps 
web.config validate:  AutoGenerate,IsolateApps 

은 물론 나는이에 의해 매우 혼란 스러워요.

나에게 잔인하게 분명해야하는 여기에 뭔가가 누락 되었습니까?

감사합니다 :)

답변

0

정적 API WebConfigurationManager.GetSection("system.web/machineKey") 대신를 사용합니다. config 계층 구조를 순회하면서 가장 적합한 응용 프로그램 (일반적으로 현재 응용 프로그램의 ~/Web.config ~)을 찾아 특정 값을 추출하는 논리를 자동으로 수행합니다.

+0

달콤한! 다음 주에이 프로젝트로 돌아올 때 검토 할 예정입니다. :) – nokturnal

관련 문제