更新时间:2023-02-16 14:54:17
DefaultHttpRequest
已从 public
更改为 internal
作为 ASP 的一部分.NET Core 3.0 版本,这意味着它不再可用.在您显示的代码中,似乎没有任何理由创建或依赖 DefaultHttpRequest
.
DefaultHttpRequest
was changed from public
to internal
as part of the ASP.NET Core 3.0 release, which means it's no longer available. In the code you've shown, there doesn't appear to be any reason to create or depend on DefaultHttpRequest
.
我建议将代码更改为如下所示:
I recommend changing the code to something like this:
private static async Task<UserInfo> Upload(byte[] buffer, FormFileCollection formFileCollection,
HttpRequest httpRequest, Dictionary<string, StringValues> dictionary)
{
// ...
httpRequest.Form = new FormCollection(dictionary, formFileCollection);
// Update all other references to defaultHttpRequest
// ...
}
public async void Test1Up() // async void is generally bad, but that's a separate issue
{
// ...
var httpContext = new DefaultHttpContext(featureCollection);
var httpRequest = httpContext.Request;
// Update all other references to defaultHttpContext and defaultHttpRequest
// ...
}
不要传递DefaultHttpRequest
,而是使用抽象的HttpRequest
.在 Upload
中设置的 Form
属性是 HttpRequest
的一部分,因此应该按原样工作.也无需创建DefaultHttpRequest
的实例:DefaultHttpContext
构造函数为您完成此操作并通过其Request提供它代码> 属性.
Rather than passing around DefaultHttpRequest
, use the abstract HttpRequest
. The Form
property being set in Upload
is part of HttpRequest
, so that should work as-is. There's also no need to create an instance of DefaultHttpRequest
: the DefaultHttpContext
constructor does this for you and provides it via its Request
property.