Search code examples
c#.netasp.net-mvcbackload

MVC Backload File Upload failing in production


I've got a .NET 4.5 MVC 5 web application that utilizes Backload 2.0 to help with uploading an Excel file. The controller method works great in my development environment. However, when I moved to my production server, the same method is now failing.

It's failing because handler.Services.POST is null. All of the other properties off handler.Services are null as well, e.g. GET, etc.

What might cause this to happen? Is it an IIS setting? Web.config? What else can I check??

Most of this code was copied from an example that ships with 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);
            }
        }

Solution

  • Direct api calls (Services namespace) is a Pro feature and only works with the Pro Edition.

    In your case I think you can switch to events with the same result. For example you can use the StoreFileRequestStarted event. Don't forget to enable events in the Web.Backload.config like described here: https://github.com/blackcity/backload/wiki/Example-12

    The demo package also includes an events example: https://github.com/blackcity/Backload/releases/download/v2.1.0.0/Backload.Standard.2.1.Full.zip