gpt4 book ai didi

c# - Stream 意外结束,内容可能已被另一个组件读取。 Microsoft.AspNetCore.WebUtilities.MultipartReaderStream

转载 作者:行者123 更新时间:2023-12-02 00:42:10 32 4
gpt4 key购买 nike

当我尝试从请求中读取多部分内容时,出现异常,表示该内容可能已被另一个组件读取。

 if (MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
{
// Used to accumulate all the form url encoded key value pairs in the
// request.
var formAccumulator = new KeyValueAccumulator();

var boundary = Request.GetMultipartBoundary();
var reader = new MultipartReader(boundary, HttpContext.Request.Body);
var section = await reader.ReadNextSectionAsync();
while (section != null)
{
ContentDispositionHeaderValue contentDisposition;
var hasContentDispositionHeader =
ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out contentDisposition);
}
}

最佳答案

asp.net core 3中,您必须添加 factories.RemoveType<FormFileValueProviderFactory>();给您DisableFormValueModelBindingAttribute属性。

代码

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class DisableFormValueModelBindingAttribute : Attribute, IResourceFilter
{
public void OnResourceExecuting(ResourceExecutingContext context)
{
var factories = context.ValueProviderFactories;
factories.RemoveType<FormValueProviderFactory>();
factories.RemoveType<FormFileValueProviderFactory>();
factories.RemoveType<JQueryFormValueProviderFactory>();
}

public void OnResourceExecuted(ResourceExecutedContext context)
{
}
}

Documentation

关于c# - Stream 意外结束,内容可能已被另一个组件读取。 Microsoft.AspNetCore.WebUtilities.MultipartReaderStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49867343/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com