我正在尝试在ASP.NET WebAPI操作中使用流模式:
我通过{p>设置了https://ibb.co/jzsjNz
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);
}
}
但是在我的WebAPI控制器操作中,该值设置为Classic而不是None ...
// 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);
}
}