Как сделать HttpContext.Current.Request.ReadEntityBodyMode равным None? - PullRequest
0 голосов
/ 02 сентября 2018

Я пытаюсь использовать режим потоковой передачи в действии 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?
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...