8

I was using the WebRequestHandler for setting the CachePolicy and AuthenticationLevel in my full stack .NET application. Now I am migrating my application to .NET core and can't find an alternative to these properties or the WebRequestHandler. Any help? Following is my usage:

        var httpClientHandler = new WebRequestHandler
        {
            UseProxy = true,
            UseCookies = false,
            CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore),
            AuthenticationLevel = AuthenticationLevel.MutualAuthRequired
        };
Amit
  • 83
  • 1
  • 5
  • 2
    You could try HttpClientHandler class (pass it as arg to HttpClient .ctor). But it doesn't have CachePolicy and AuthenticationLevel. I guess your solution may not lie in one handler instance. Btw, I use this to bypass SSL certificate errors. – Andrei Floroiu Apr 07 '17 at 10:51

1 Answers1

7

CachePolicy:

There is no equivalent to CachePolicy in .NET Core. However, .NET Core is equivalent to RequestCacheLevel.BypassCache. I confirmed that in this GitHub issue.

So while there is no built-in CachePolicy, this design enables you to build your own cache on top of HttpClient using any policy you like.

AuthenticationLevel:

WebRequest in .NET Core offers an AuthenticationLevel property, but that won't help you much if you need to use HttpClient.

You could implement a custom HttpMessageHandler to pass into HttpClient that supports AuthenticationLevel. To make it easier to implement, you could base it off an existing HttpMessageHandler such as the Windows one.

Community
  • 1
  • 1
Daniel Crabtree
  • 716
  • 4
  • 8