2011-10-20 2 views
1

로드 밸런서에서 내 사이트를 실행해야하므로 세션 토큰 처리기를 다음으로 대체해야했습니다.로드 밸런서를 사용하여 시작 및 신뢰 당사자

public class WebFarmSessionSecurityTokenHandler : SessionSecurityTokenHandler 
{ 
    public WebFarmSessionSecurityTokenHandler(X509Certificate2 protectionCertificate) 
     : base(CreateRsaTransforms(protectionCertificate)) 
    { } 

    private static ReadOnlyCollection<CookieTransform> CreateRsaTransforms 
     (X509Certificate2 protectionCertificate) 
    { 
     var transforms = new List<CookieTransform>() 
         { 
          new DeflateCookieTransform(), 
          new RsaEncryptionCookieTransform(protectionCertificate), 
          new RsaSignatureCookieTransform(protectionCertificate), 
         }; 

     return transforms.AsReadOnly(); 
    } 
} 

다음과 같이 web.config를 수정했습니다.

<microsoft.identityModel> 
    <service> 
... 
    <securityTokenHandlers> 
     <clear /> 
     <add type="MyAssembly.WebFarmSessionSecurityTokenHandler, MyAssembly"/> 
    </securityTokenHandlers> 
... 
    </service> 
</microsoft.identityModel> 

내 희망은 내 신뢰 당사자가 어떤 노드에 액세스했는지 또는 어떤 상자가 인증을 시작했는지 상관없이 작동한다는 것이 었습니다.

현재 다음과 같이 표시됩니다. SecurityTokenHandler가 보안 토큰을 읽을 수 있도록 등록되지 않았습니다.

아이디어가 있으십니까?

답변

2
void onServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e) 
     { 
      List<CookieTransform> sessionTransforms = new List<CookieTransform>(new CookieTransform[] 
      { 
       new DeflateCookieTransform(), 
       new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate), 
       new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate) 
      }); 

      SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly()); 
      e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler); 
     } 

위의 내용은 global.asax 파일 내에 있어야합니다. 응용 프로그램 시작시 다음 이벤트가 연결됩니다.

FederatedAuthentication.ServiceConfigurationCreated += onServiceConfigurationCreated; 

나는 더 이상 WebFarmSessionSecurityTokenHandler 또는 그것을 슬롯으로 설정 변경을 할 필요가 없습니다.

관련 문제