您好我正在使用asp.net mvc5上传一个大文件到服务器和控制器我将此流保存到TempData.on我的本地机器它工作正常并成功上传大文件。但在托管服务器上它fails.i已经尝试过增加MaxAllowedContent和ExcutionTimeOut Limit但没有一个工作。任何人都可以帮助我。
这是我的控制器动作
public ActionResult UploadTransactionPDF()
{
private readonly List<MemoryStream> _PdfImage = new List<MemoryStream>();
private readonly List<string> _PdfImageNames = new List<string>();
try
{
Gateway.Instance.Logger.LogInfo(string.Format(_formatProvider,"[TransactionController -> UploadTransactionPDF ]: method started : Save pdf to memory."));
if (CheckFileExist())
{
if (TempData[TransactionRef.PdfFiles.ToString()] != null)
{
_PdfImage.Clear();
_PdfImage.AddRange(TempData[TransactionRef.PdfFiles.ToString()] as List<MemoryStream>);
}
if (TempData[TransactionRef.PdfFileName.ToString()] != null && !string.IsNullOrEmpty(TempData[TransactionRef.PdfFileName.ToString()].ToString()))
{
_PdfImageNames.Clear();
_PdfImageNames.AddRange(TempData[TransactionRef.PdfFileName.ToString()] as List<string>);
}
for (int a = 0; a < Request.Files.Count; a++)
{
if (!_PdfImageNames.Contains(Request.Files[a].FileName))
{
MemoryStream ms = new MemoryStream();
Request.Files[a].InputStream.CopyTo(ms);
_PdfImage.Add(ms);
_PdfImageNames.Add(Request.Files[a].FileName);
}
}
TempData[TransactionRef.PdfFiles.ToString()] = _PdfImage;
TempData[TransactionRef.PdfFileName.ToString()] = _PdfImageNames;
ViewBag.Info = "pdf";
ViewBag.ImageUploadInfo = Language.ImageSavedMessage.ToString();
}
else
{
ViewBag.ImageUploadInfo = Language.NoFileMessage.ToString();
}
ViewBag.FileNames = _PdfImageNames;
Gateway.Instance.Logger.LogInfo(string.Format(_formatProvider, "[TransactionController -> UploadTransactionPDF ] : method exited ."));
return View("_PDFFiles");
}
catch (Exception ex)
{
string errorInfo = string.Format(_formatProvider, "[TransactionController -> UploadTransactionPDF ] : Error : '{0}' occurred while saving pdf to memory.",ex.Message);
Gateway.Instance.Logger.LogError(errorInfo,ex);
throw new Exception(errorInfo, ex);
}
}
谢谢!
答案 0 :(得分:0)
您可以查看开发环境中的web.config与服务器上是否存在以下内容。 ddddd应该是您的请求应允许的最大值。不要把它打到你打开DOS的地方。请求长度不仅仅是文件大小,而是从客户端到服务器的整个请求。
<configuration>
<system.web>
<httpRuntime targetFramework="4.5" maxRequestLength="ddddd" />
</system.web>
</configuration>
您可以通过在配置和system.web元素之间添加位置元素,将其本地化为一个控制器操作。