.NET Core中WebRequestHandler的替代方法是什么? [英] What's the alternative to WebRequestHandler in .NET Core?

查看:368
本文介绍了.NET Core中WebRequestHandler的替代方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WebRequestHandler 在我的整个.NET应用程序中设置 CachePolicy AuthenticationLevel 。现在,我正在将应用程序迁移到.NET Core,找不到这些属性或WebRequestHandler的替代方法。有什么帮助吗?以下是我的用法:

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
        };


推荐答案

CachePolicy:



.NET Core中没有等效于CachePolicy的内容。但是,.NET Core等效于RequestCacheLevel.BypassCache。我在此GitHub问题中确认

因此,虽然没有内置的CachePolicy,但此设计使您可以使用所需的任何策略在HttpClient之上构建自己的缓存。

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.

.NET Core中的WebRequest提供了AuthenticationLevel属性,但是如果您需要使用HttpClient,那将无济于事。

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

您可以实现一个自定义HttpMessageHandler,以传递到支持AuthenticationLevel的HttpClient中。为了使其更容易实现,您可以将其基于现有的HttpMessageHandler,例如 Windows操作系统

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.

这篇关于.NET Core中WebRequestHandler的替代方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆