zoukankan      html  css  js  c++  java
  • web api 2.0 上传文件超过4M时,出现404错误

    客户端代码

    string path = "C:\text.txt";
    WebClient client = new WebClient();
    Uri _address = new Uri(_baseAddress, "/api/Basedata/UploadDat/");
    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//长度
    client.UploadFile(_address, "POST", path);

    服务器端代码

    [HttpPost]
            public void UploadDat()
            {
                HttpPostedFile file = HttpContext.Current.Request.Files[0];
                string strPath = ConfigurationManager.AppSettings["UploadServerDatPath"];
                if (!Directory.Exists(strPath))
                {
                    Directory.CreateDirectory(strPath);
                }
                string Path = strPath + file.FileName;
                file.SaveAs(Path);
            }

    部署后,上传大于4M的文件出现404错误,说明根本就没有找到这个服务器地址。

    首先,web api有设置默认上传文件大小最大是4M,在服务器端的web.config中需要添加如下配置:

    <httpRuntime targetFramework=“4.5” maxRequestLength="2097152" executionTimeout="3600"/>

    另外,IIS也要做修改,请求筛选-->编辑功能设置-->允许的最大内容长度改为2147483648,并重新启动服务。

  • 相关阅读:
    springmvc+mybatis多数据源切换
    Tomcat 8.5 配置自动从http跳转https
    Tomcat 8.5 配置 域名绑定
    本地测试Tomcat配置Https访问
    Spring boot
    解决IDEA16闪退的问题
    cef
    spring-boot学习资料
    oracle 表空间不足解决办法
    oracle导出表的办法
  • 原文地址:https://www.cnblogs.com/ttssrs/p/6737324.html
Copyright © 2011-2022 走看看