MVC Backload 文件上传在生产中失败

MVC Backload File Upload failing in production

我有一个 .NET 4.5 MVC 5 Web 应用程序,它利用 Backload 2.0 来帮助上传 Excel 文件。控制器方法在我的开发环境中效果很好。但是,当我转移到我的生产服务器时,同样的方法现在失败了。

失败,因为 handler.Services.POST 为空。 handler.Services 的所有其他属性也为 null,例如GET,等等

什么可能导致这种情况发生?它是IIS设置吗? Web.config?我还能检查什么??

大部分代码是从 Backload 附带的示例中复制的。

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post | HttpVerbs.Put | HttpVerbs.Delete | HttpVerbs.Options)]
        public async Task<ActionResult> FileHandler()
        {
            try
            {
                // Create and initialize the handler
                var handler = Backload.FileHandler.Create();
                handler.Init(HttpContext.Request);

                // Call the appropriate request handlers
                if (handler.Context.HttpMethod == "POST")
                {
                    // Get the posted file with meta data from the request
                    handler.FileStatus = await handler.Services.POST.GetPostedFiles();

                    if (handler.FileStatus != null)
                    {
                        var file = handler.FileStatus.Files[0];

                        DateTime spreadsheetDate;

                        using (var memoryStream = new MemoryStream((int)file.FileSize))
                        {
                            await file.FileStream.CopyToAsync(memoryStream);

                            //TODO: do some stuff...
                        }
                    }

                    // Create client plugin specific result and return an ActionResult
                    IBackloadResult result = handler.Services.Core.CreatePluginResult();
                    return ResultCreator.Create((IFileStatusResult)result);
                }

                // other http methods may also be handled
                return new EmptyResult();
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
            }
        }

直接 api 调用(服务命名空间)是专业版功能,仅适用于专业版。

在你的情况下,我认为你可以切换到具有相同结果的事件。例如,您可以使用 StoreFileRequestStarted 事件。不要忘记启用 Web.Backload.config 中的事件,如下所述: https://github.com/blackcity/backload/wiki/Example-12

演示包还包括一个事件示例: https://github.com/blackcity/Backload/releases/download/v2.1.0.0/Backload.Standard.2.1.Full.zip