use*_*677 3 c# .net-core asp.net-core
我刚刚从 2.1 升级到 .net core 3.1。
我更新了所有软件包,但出现以下无法解决的错误:
The type or namespace name 'DefaultHttpRequest' could not be found
The type or namespace name 'Internal' does not exist in the namespace 'Microsoft.AspNetCore.Http'
Run Code Online (Sandbox Code Playgroud)
我一直在上面使用:
using Microsoft.AspNetCore.Http.**Internal**;
private static async Task<UserInfo>
Uplpoad(byte[] buffer, FormFileCollection formFileCollection,
**DefaultHttpRequest defaultHttpRequest,**
Dictionary<string, StringValues> dictionary)
{
//some code
defaultHttpRequest.Form = new FormCollection(dictionary, formFileCollection);
//some code
}
public async void Test1Up()
{
//some code
var defaultHttpContext = new DefaultHttpContext(featureCollection);
var defaultHttpRequest = new **DefaultHttpRequest**(defaultHttpContext);
//some code
}
Run Code Online (Sandbox Code Playgroud)
请参阅 ** 中突出显示的行中的错误
我可以在 3.1 的重大更改中看到 DefaultHttpContext 发生了更改,但我没有找到任何与DefaultHttpRequest上述错误相关的内容。
Kir*_*kin 11
DefaultHttpRequest作为 ASP.NET Core 3.0 版本的一部分从 更改public为internal,这意味着它不再可用。在您显示的代码中,似乎没有任何理由创建或依赖DefaultHttpRequest.
我建议将代码更改为如下所示:
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
// ...
}
Run Code Online (Sandbox Code Playgroud)
与其四处传递,不如DefaultHttpRequest使用摘要HttpRequest。Form设置的属性是Upload的一部分HttpRequest,因此应该按原样工作。也不需要创建的实例DefaultHttpRequest:DefaultHttpContext构造函数会为您执行此操作并通过其Request属性提供它。
| 归档时间: |
|
| 查看次数: |
5976 次 |
| 最近记录: |