What's the alternative to WebRequestHandler in .NET Core?
I used WebRequestHandler to set CachePolicy and AuthenticationLevel in my complete .NET application. Now I am porting my application to .NET core and cannot find an alternative to these properties or WebRequestHandler. Any help? Below is my usage:
var httpClientHandler = new WebRequestHandler
{
UseProxy = true,
UseCookies = false,
CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore),
AuthenticationLevel = AuthenticationLevel.MutualAuthRequired
};
source to share
CachePolicy:
There is no CachePolicy equivalent in .NET Core. However .NET Core is equivalent to RequestCacheLevel.BypassCache. I confirmed that in this GitHub question .
So, while there is no built-in CachePolicy, this construct allows you to create your own cache on top of the HttpClient using whatever policy you like.
AuthenticationLevel:
WebRequest in .NET Core offers an AuthenticationLevel property, but that won't help you if you need to use HttpClient.
You can implement a custom HttpMessageHandler to pass to an HttpClient that supports AuthenticationLevel. To simplify the implementation, you can create it from an existing HttpMessageHandler like Windows one .
source to share