我有一个 .NET 4.5 MVC 5 Web 应用程序,它利用 Backload 2.0 帮助上传 Excel 文件。控制器方法在我的开发环境中效果很好。但是,当我移至生产服务器时,同样的方法现在失败了。
它失败了,因为它handler.Services.POST
是空的。所有其他属性 offhandler.Services
也为 null,例如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);
}
}