0

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);
            }
        }
John Russell
  • 2,177
  • 4
  • 26
  • 47

1 Answers1

0

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

helgans
  • 343
  • 2
  • 7
  • Thanks for the feedback. Why would this approach work fine in development mode? – John Russell Dec 01 '15 at 20:05
  • Events are a Standard feature. There are some advanced config settings and the API methods in the "Services" namespace only available in the Pro edition. Limitations: https://github.com/blackcity/backload/wiki/editions. You can assign your memory stream to the "IFileStatusItem" object in the event parameter. – helgans Dec 02 '15 at 10:03
  • One side note: If remember right, the stream is automatically closed/disposed after it is processed/saved, so you need to take this into account. Do not close the stream (using statement), because the internal processes do not have access to it anymore. You can check the status of the stream in the Finished event if you want. – helgans Dec 02 '15 at 10:11