Skip to content

Commit ae0673b

Browse files
committed
Fixed sample
1 parent 82db14c commit ae0673b

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

snippets/csharp/System.Net.Http/WinHttpHandler/Project.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
</PropertyGroup>
7-
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="9.0.6" />
10+
</ItemGroup>
11+
812
</Project>
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
using System;
22
using System.Net;
33
using System.Net.Http;
4-
using System.Net.Sockets;
5-
using System.Threading.Tasks;
4+
using System.Net.Security;
65

76
class WinHttpHandler_SecureExample
87
{
9-
static async Task Main()
8+
static void Main()
109
{
10+
if (!OperatingSystem.IsWindows())
11+
{
12+
Console.WriteLine("This example requires Windows.");
13+
return;
14+
}
1115
// <Snippet1>
1216
var handler = new WinHttpHandler();
13-
handler.ServerCertificateValidationCallback = (httpRequestMessage, certificate, chain, sslPolicyErrors)
17+
handler.ServerCertificateValidationCallback = (httpRequestMessage, certificate, chain, sslPolicyErrors) =>
1418
{
15-
if (sslPolicyErrors == SslPolicyErrors.None)
19+
if (sslPolicyErrors == SslPolicyErrors.None)
20+
{
21+
// TODO: Implement additional custom certificate validation logic here.
1622
return true;
17-
18-
Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
19-
23+
}
2024
// Do not allow this client to communicate with unauthenticated servers.
2125
return false;
22-
}
26+
};
2327
// </Snippet1>
2428
}
2529
}

0 commit comments

Comments
 (0)