我發現這個代碼:如何翻譯這個C#代碼來檢測當前信任級別ASP.NET應用到VB.Net
AspNetHostingPermissionLevel GetCurrentTrustLevel() {
foreach (AspNetHostingPermissionLevel trustLevel in
new AspNetHostingPermissionLevel [] {
AspNetHostingPermissionLevel.Unrestricted,
AspNetHostingPermissionLevel.High,
AspNetHostingPermissionLevel.Medium,
AspNetHostingPermissionLevel.Low,
AspNetHostingPermissionLevel.Minimal
})
{
try {
new AspNetHostingPermission(trustLevel).Demand();
}
catch (System.Security.SecurityException) {
continue;
}
return trustLevel;
}
return AspNetHostingPermissionLevel.None;
}
從Get current ASP.NET Trust Level programmatically,但是這是C#,我想有它爲VB.NET。 在VB.NET和C#中都可以將其轉換爲VB代碼的專家的任何機會?
我試着自己,得到了下面的VB.NET代碼,但它產生我VWD內部的錯誤:
Private Function GetCurrentTrustLevel() As AspNetHostingPermissionLevel
For Each trustLevel As AspNetHostingPermissionLevel In New _
AspNetHostingPermissionLevel() { _
AspNetHostingPermissionLevel.Unrestricted, _
AspNetHostingPermissionLevel.High, _
AspNetHostingPermissionLevel.Medium, _
AspNetHostingPermissionLevel.Low, _
AspNetHostingPermissionLevel.Minimal _
}
Try
New AspNetHostingPermission(trustLevel).Demand()
Catch generatedExceptionName As System.Security.SecurityException
Continue Try
End Try
Return trustLevel
Next
Return AspNetHostingPermissionLevel.None
End Function
這些部件似有不妥:
New AspNetHostingPermission(trustLevel).Demand()
和
Continue Try
很明顯,需要有人通過處理NT在C#和VB.NET,可以在VB.NET
發現錯誤感謝
拉爾斯
嘗試加載它在反射器,並選擇顯示它在VB.Net。通常工作。 http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1 –
感謝您的提示!下一次我遇到類似的C#vs VB.NET問題時,我會研究一下。 Lars – lars