Warning issued on VS 2005:
'System.Net.ServicePointManager.CertificatePolicy' is obsolete: 'CertificatePolicy' is obsoleted for this type, please use ServerCertificateValidationCallback instead.
Is this change Security related or has been done to do thing differently
Any pointers will be helpful.

'CertificatePolicy' Vs 'ServerCertificateValidationCallback'
dlyford
In VB.NET 2003 this was done according to:
http://support.microsoft.com/default.aspx scid=kb;en-us;823177
In VB.NET 2005, after a good amount of playing around, I came up with the following based on the post above. I don't know how "correct" this is, but it seems to work as a 2005 version of the KB article. Hope this helps someone else.
====================
Imports System.Net
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Public Class MyClass
Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean'Return True to force the certificate to be accepted.
Return True
End Function Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
End Sub
End Class
====================
Ling Chen Wu
does not work with VS 2003 (C#)
Ri
That code uses an anonymous delegate in C#, to translate it to VB you'd need to pull the validation code out into a seperate function. It'd look similar to:
Private Function ValidateCertificate(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) As Boolean
Dim validationResult As Boolean
validationResult = False
'
' policy code here ...
'
Return validationResult
End Function
AddHandler servicePointManager.ServerCertificateValidationCallback, AddressOf ValidateCertificate
-Shawn
rebecca
NorCis
Fafa
At the expense of sounding like a newbie, can you provide a VB 2005 translation
I had the "work around" in 2003 and I am trying to provide the same functionality in 2005.
(I tried a few stabs with AddHandler with no luck)
Thanks in advance!
servicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool validationResult = false;
//
// policy code here ...
//
return validationResult
};
sobrle
samithad
If you need the same code base to compile on both frameworks, then you'll either have to conditionally compile (#ifdef WHIDBEY), or use the old CertificatePolicy member. If you choose to go the second route, you can surround the setting of CertificatePolicy with #pragma warning disable <warning number> and #pragma warning enable <warning number> on Whidbey.
-Shawn
ChristerHe
The new API isn't a security patch, however it does provide a nicer programming model than the old way of doing things, especailly combined with C# 2.0's anonymous delegate feature. For instance, you can now do something along the lines of:
servicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool validationResult = false;
//
// policy code here ...
//
return validationResult
};
Whereas the old programming model required you to either create a seperate class that implemented that method, or implement the ICertificatePolicy interface yourself.
-Shawn
keyler
I got an idea about implementation But our issue is:
We got our code written with VS2003 (1.1 framework). Now, we want the same code to work on both frameworks(1.1 and 2.0), irrespective of what framework our customer has installed at his end.
The solutions we've reached so far are:
1. Maintain two different code bases each for a version of framework. Certainly the most easier to implement, but equally difficult to maintain.
2. Use reflection to achieve desired result. But as we understand, in Framework 2.0, System.Reflection.Assembly.LoadFromPartialPath(String) is also deprected which would allow us to load the desired assembly from GAC without bothering about the physical location of the assembly. So this makes it more difficult.
Would like to know your views on this.
Regards,
Prajkta