【问题标题】:MVC Backload File Upload failing in productionMVC 后载文件上传在生产中失败
【发布时间】:2016-03-05 11:37:22
【问题描述】:

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

它失败了,因为handler.Services.POST 为空。 handler.Services 之外的所有其他属性也为空,例如GET

什么可能导致这种情况发生?它是IIS设置吗?网络配置?我还能检查什么??

大部分代码都是从 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);
            }
        }

【问题讨论】:

    标签: c# .net asp.net-mvc backload


    【解决方案1】:

    直接 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

    【讨论】:

    • 感谢您的反馈。为什么这种方法在开发模式下可以正常工作?
    • 事件是标准功能。 “服务”命名空间中的一些高级配置设置和 API 方法仅在专业版中可用。限制:github.com/blackcity/backload/wiki/editions。您可以将内存流分配给事件参数中的“IFileStatusItem”对象。
    • 附注:如果没记错的话,流在处理/保存后会自动关闭/处置,因此您需要考虑到这一点。不要关闭流(using 语句),因为内部进程无法再访问它。如果需要,您可以在 Finished 事件中检查流的状态。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 2021-03-13
    • 2014-02-15
    • 2016-08-10
    • 2022-08-17
    • 1970-01-01
    • 2021-06-02
    相关资源
    最近更新 更多