asp.net-core – Stream的意外结束,内容可能已被另一个组件读取.
发布时间:2020-12-16 07:07:09 所属栏目:asp.Net 来源:网络整理
导读:当我尝试从请求中读取多部分内容时,我得到一个异常,说明内容可能已被其他组件读取. if (MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { // Used to accumulate all the form url encoded key value pairs in the // request. var f
当我尝试从请求中读取多部分内容时,我得到一个异常,说明内容可能已被其他组件读取.
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); } } 解决方法
事实证明,我必须使用下面的属性禁用表单值模型绑定.
[HttpPost] [Route("")] [DisableFormValueModelBinding] public async Task<IActionResult> Post() 属性实现如下 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class DisableFormValueModelBindingAttribute : Attribute,IResourceFilter { public void OnResourceExecuting(ResourceExecutingContext context) { var factories = context.ValueProviderFactories; factories.RemoveType<FormValueProviderFactory>(); factories.RemoveType<JQueryFormValueProviderFactory>(); } public void OnResourceExecuted(ResourceExecutedContext context) { } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – MVC 5中的TryUpdate()和Update()方法有什么
- 剃刀 – 在身份3中创建声明身份
- ASP.NET GridView CommandField作为TemplateField
- ASP.NET MVC 2 – ViewModel前缀
- asp.net-web-api – ASP.NET WebApi自定义序列化
- asp.net-mvc – ASP.Net MVC不显眼的日期范围验证
- asp.net – 从SqlMembershipProvider迁移到自定义提供程序
- asp.net – 如何将查询字符串添加到facebook登录按钮的redi
- 什么是ASP.NET-MVC 5.1中的ManageController.cs及其创建原因
- asp.net-mvc – 搜索页面MVC路由(隐藏动作,没有斜线,如SO)
推荐文章
站长推荐
- asp.net – Visual Studio 2012 – 哪里有ASPX设
- .net – 类库项目中特定于语言的资源文件的问题
- asp.net – 我可以修改Request.Headers集合吗?
- ASP.NET MVC中的静态文件授权与Owin
- asp.net – “Aspnetdb”数据库中的所有表用于什
- asp-classic – 如何清除所有cookie?
- asp.net-mvc – Ninject如何在ASP.NET MVC中创建
- asp.net-mvc – MVC – 索引视图溢出
- ASP.NET MVC Controller FileContent ActionResu
- asp.net-mvc – 如何在响应重定向MVC后保留Serve
热点阅读