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,并重新启动服务。

 

转载于:https://www.cnblogs.com/ttssrs/p/6737324.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值