简体   繁体   English

调用 HttpRequest.GetBufferlessInputStream 后不支持此方法或属性 request.Files

[英]This method or property is not supported after HttpRequest.GetBufferlessInputStream has been invoked request.Files

I am using ASP.NET FW 4.6.1;我正在使用 ASP.NET FW 4.6.1; Microsft.AspNet.WebApi 5.2.7; Microsft.AspNet.WebApi 5.2.7; EF 6.4.英孚 6.4。

I have the issue below when starting my project.我在开始我的项目时遇到以下问题。

Method request.Files is not supported (please see image)方法 request.Files 不被支持(请看图)

在此处输入图像描述

public static class WebApiConfig
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "<Pending>")]
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        //Enable cross domain request
        EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
        config.EnableCors(cors);

        config.Filters.Add(new ErrorHandlers.AiHandleErrorAttribute());
        **config.Filters.Add(new UploadFileFilterAttribute());**

        config.MessageHandlers.Add(new RequestTabletMessageHandler());
        config.MessageHandlers.Add(new RequestLoggingMessageHandler());

        config.Services.Add(typeof(IExceptionLogger), new CustomExceptionLogger());            
    }
}

The reason it is not supported is because the file buffer stream has already been parsed (or parsing has started) at a previous point in the request pipeline.不支持它的原因是文件缓冲区 stream 已经在请求管道的前一点被解析(或解析已经开始)。 You should look at other filters/modules in your pipeline and see if any of them touch the files in the incoming request.您应该查看管道中的其他过滤器/模块,看看它们中的任何一个是否触及传入请求中的文件。 You might find that simply commenting out other filters (such as ErrorHandlers.AiHandleErrorAttribute() for example) and rerunning could be used to quickly determine which filter/module is doing the parsing.您可能会发现简单地注释掉其他过滤器(例如ErrorHandlers.AiHandleErrorAttribute() )并重新运行可用于快速确定哪个过滤器/模块正在执行解析。 Once you have figured that out, you need to decide how you are going to handle multiple parses of the files.弄清楚这一点后,您需要决定如何处理文件的多个解析。 One option is to only use one module, another would be to buffer it into a memory stream/block of memory and have both/all modules access that copy instead.一种选择是仅使用一个模块,另一种是将其缓冲到 memory 的 memory 流/块中,并让两个/所有模块都访问该副本。 Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM