我正在尝试将以下代码转换为 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”语句来引发事件。
有人可以帮我转换代码吗?