【问题标题】:upload video in app_data folder more then 4MB mvc [duplicate]在 app_data 文件夹中上传视频超过 4MB mvc [重复]
【发布时间】:2017-03-23 15:51:45
【问题描述】:
if (Request.Files.Count > 0)
{
    try
    {
        //  Get all files from Request object  
        HttpFileCollectionBase files = Request.Files;
        for (int i = 0; i < files.Count; i++)
        {
            HttpPostedFileBase file = files[i];
            // Checking for Internet Explorer  
            if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
            {
                string[] testfiles = file.FileName.Split(new char[] { '\\' });
                fname +=testfiles[testfiles.Length - 1];
            }
            else
            {
                fname +=file.FileName;
            }

            response = new
            {
                status = true,
                message = fname
            };
            // Get the complete folder path and store the file inside it.  
            fname = Path.Combine(Server.MapPath("~/App_Data/ClientVideos/"), fname);
            file.SaveAs(fname);
            
        }

      return  Json(response, JsonRequestBehavior.AllowGet);
    }
    catch (Exception ex)
    {
        response = new
        {
            status = false,
            message = "Error occurred. Error details: " + ex.Message
        };
        return Json(response, JsonRequestBehavior.AllowGet);                    
    }
}

【问题讨论】:

  • 更改您的 web.config 以更改最大请求大小。

标签: c# asp.net-mvc


【解决方案1】:

在您的 web.config 中增加 maxAllowedContentLength

<system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>

值以字节为单位。

【讨论】:

  • 我使用的是 IIS 10,它不工作
  • 它给出了错误-HTTP错误500.19-内部服务器错误请求的页面无法访问,因为该页面的相关配置数据无效。
  • 答案已更新,请参阅上面的重复 Q
  • 也将值从 KB 更改为字节
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-23
  • 1970-01-01
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 2023-03-29
  • 2017-04-02
相关资源
最近更新 更多