amo*_*mol 6 c# asp.net rest servicestack
我正在尝试将大型excel文件发送到其余服务(使用servicestack).
客户端和服务器(Servicestack服务)应用程序部署在不同的服务器上.
我在客户端使用以下代码上传excel文件(8 MB大小)
取自
http://www.codeproject.com/Articles/501608/Sending-Stream-to-ServiceStack
HttpWebRequest client = (HttpWebRequest)WebRequest
.Create(ConfigurationManager
.AppSettings["applicationUrl"]
+ @"/servicename/"
+ fileUpload.FileName
+ @"/" + FileType + @"/"
+ Utility.UserName + @"/"
+ Utility.EmployerID + @"/"
+ UploadedFrom);
client.Method = WebRequestMethods.Http.Post;
////the following 4 rows enable streaming
client.AllowWriteStreamBuffering = false;
client.SendChunked = true;
client.ContentType = "multipart/form-data;";
client.Timeout = int.MaxValue;
// client.KeepAlive = false;
//client.ProtocolVersion = HttpVersion.Version10;
//client.ContentLength = 0;
//client.Timeout = Timeout.Infinite;
//client.AllowWriteStreamBuffering = true;
Stream stream = fileUpload.InputStream;
if (stream.CanRead)
{ stream.Copy(client.GetRequestStream());
}
var response = new StreamReader(client.GetResponse().GetResponseStream()).ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
当上传的文件是2-3 MB时,上面的代码工作正常.当文件大小约为8MB时,它会抛出错误.
调试它时会出现以下错误
System.Net.WebException was caught
HResult=-2146233079
Message=The remote server returned an error: (500) Internal Server Error.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Myproject.Web.Controllers
.Employer.FileUploadController
.Upload(FileUploadViewModel fileUploadViewModel
,HttpPostedFileBase fileUpload
,String DataFileType
,String UploadedFrom)
in d:\MyProject\projNewArch\Controllers\Employer\FileUploadController.cs:line 262
InnerException:
Run Code Online (Sandbox Code Playgroud)
我试过更改可以看作连接的设置值.
可能是什么问题?请帮忙
更新1:我在服务器上有IIS 8.5,所以我认为文件大小(8mb)可能不是问题.我是否仍需要在web.config中添加一些设置以允许通过POST发送大尺寸文件
更新2:找到解决方案.添加maxAllowedContentLength和maxRequestLength就可以了.请在评论部分查看Smartdev提供的链接
您仍然需要编辑 web.config 文件。它应该看起来像这样:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10485760" />
</requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)
这将允许您上传最多 10MB
| 归档时间: |
|
| 查看次数: |
652 次 |
| 最近记录: |