次のコードをVB.netに変換しようとしています
private void Application_Start(object sender, EventArgs e)
{
var defaultTableData = new DefaultTableData();
defaultTableData.CheckAndUpdate();
if (ConfigurationManager.AppSettings["RSAConfigSwitch"].ToString().ToUpper() == "ON")
{
FederatedAuthentication.ServiceConfigurationCreated += new EventHandler<ServiceConfigurationCreatedEventArgs>(FederatedAuthentication_ServiceConfigurationCreated);
}
}
void FederatedAuthentication_ServiceConfigurationCreated(object sender, Microsoft.IdentityModel.Web.Configuration.ServiceConfigurationCreatedEventArgs e)
{
String certName = ConfigurationManager.AppSettings["CertificateName"].ToString(); // read from web.config
System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
System.Security.Cryptography.X509Certificates.X509Certificate2Collection col = store.Certificates.Find(System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, certName, true);
var cookieProtectionCertificate = col[0];
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(
new SessionSecurityTokenHandler(new System.Collections.ObjectModel.ReadOnlyCollection<CookieTransform>(
new List<CookieTransform>
{
new DeflateCookieTransform(),
new RsaEncryptionCookieTransform(cookieProtectionCertificate),
new RsaSignatureCookieTransform(cookieProtectionCertificate)
})
));
}
変換された VB コード
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
FederatedAuthentication.ServiceConfigurationCreated += New EventHandler(Of ServiceConfigurationCreatedEventArgs)(FederatedAuthentication_ServiceConfigurationCreated)
End Sub
Private Sub FederatedAuthentication_ServiceConfigurationCreated(ByVal sender As Object, ByVal e As Microsoft.IdentityModel.Web.Configuration.ServiceConfigurationCreatedEventArgs)
Try
Dim appCertificateName As String = System.Configuration.ConfigurationManager.AppSettings("adfsCertName")
If String.IsNullOrEmpty(appCertificateName) Then
Throw New Exception("ADFS_CERTIFICATE in config is empty")
End If
Dim store As X509Store = New X509Store(StoreName.My, StoreLocation.LocalMachine)
store.Open(OpenFlags.ReadOnly)
Dim col As X509Certificate2Collection = store.Certificates.Find(X509FindType.FindBySubjectName, appCertificateName, True)
Dim cookieProtectionCertificate As X509Certificate2 = col(0)
e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(New SessionSecurityTokenHandler(New System.Collections.ObjectModel.ReadOnlyCollection(Of CookieTransform)(New List(Of CookieTransform)() With { _
New DeflateCookieTransform(), _
New RsaEncryptionCookieTransform(cookieProtectionCertificate), _
New RsaSignatureCookieTransform(cookieProtectionCertificate) _
})))
Catch ex As Exception
Throw ex
End Try
End Sub
しかし、次のエラー エラー 103 'Public Shared Event ServiceConfigurationCreated(sender As Object, e As Microsoft.IdentityModel.Web.Configuration.ServiceConfigurationCreatedEventArgs)' はイベントであり、直接呼び出すことはできません。「RaiseEvent」ステートメントを使用してイベントを発生させます。
誰かがコードの変換を手伝ってくれますか?