c# - 如何将 HttpContext.Current.Request.ReadEntityBodyMode 设置为 None?
问题描述
我正在尝试在 ASP.NET WebAPI 操作中使用流模式:
我Startup.cs
设置
public static void Configuration(IAppBuilder app)
{
if (HostingEnvironment.IsHosted)
{
GlobalConfiguration.Configure(config => Configuration(app, config));
GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new CustomWebHostBufferPolicySelector());
}
else
{
var config = new HttpConfiguration();
Configuration(app, config);
}
}
处理缓冲区/流模式的类
// Try the worst case, everything has to be streamed...
public class CustomWebHostBufferPolicySelector : WebHostBufferPolicySelector
{
// Check incoming requests and modify their buffer policy
public override bool UseBufferedInputStream(object hostContext)
{
return false;
}
// You could also change the response behaviour too...but for this example, we are not
// going to do anything here...
// I override this method just to demonstrate the availability of this method.
public override bool UseBufferedOutputStream(System.Net.Http.HttpResponseMessage response)
{
return base.UseBufferedOutputStream(response);
}
}
但是在我的 WebAPI 控制器操作中,值设置为 Classic 而不是 None...
[Route("api/v1/presentations/{presentationId:int}/documents/{documentId}")]
public async Task<HttpResponseMessage> Post(int presentationId, string documentId)
{
try
{
var readEntityBodyMode = HttpContext.Current.Request.ReadEntityBodyMode;
// Classic... but why?
解决方案
推荐阅读
- spring - 多个 Spring 集成任务执行器从 JMS 队列中获取相同的消息
- powershell - Powershell命令提取执行微软云协议的客户列表
- swift - var button = uibutton() 和 var button1: uibutton() 有什么区别
- python-3.x - 从 TF 数据集写入 tfrecords 文件
- swift - swift circle 不规则层
- protractor - 如何通过量角器将xml文件转换为excel。任何想法?
- c# - Windows 10 上的 RabbitMQ
- ruby - 转义 Ruby CSV 中的特定字符
- css - 动画播放状态暂停不工作即
- r - pam 无法访问在函数中创建的变量