【发布时间】:2019-06-20 08:57:05
【问题描述】:
当我尝试通过 IIS/服务器上传文件时,我总是收到以下错误消息,它在本地工作,但在服务器上,它总是有这个问题。
有人知道可能是什么问题吗?
错误信息:
调用事件处理程序失败: Microsoft.AspNetCore.Connections.ConnectionResetException:现有的 连接被远程主机强行关闭---> System.Net.Sockets.SocketException:现有连接是 被远程主机强行关闭 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitable.GetResult() 在 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.ProcessReceives() 在 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive() --- 内部异常堆栈跟踪结束 --- 在 System.IO.Pipelines.PipeCompletion.ThrowLatchedException() 在 System.IO.Pipelines.Pipe.GetReadResult(ReadResult& 结果) 在 System.IO.Pipelines.Pipe.GetReadAsyncResult() 在 System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 令牌)
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.PumpAsync() 在 System.IO.Pipelines.PipeCompletion.ThrowLatchedException() 在 System.IO.Pipelines.Pipe.GetReadResult(ReadResult& 结果) 在 System.IO.Pipelines.Pipe.ReadAsync(CancellationToken 令牌)在 System.IO.Pipelines.Pipe.DefaultPipeReader.ReadAsync(CancellationToken 取消令牌)在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.ReadAsync(Memory1 buffer, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory1 缓冲区,CancellationToken 取消令牌)在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] 缓冲区,Int32 偏移量,Int32 计数)在 Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.Read(字节 [] 缓冲区,Int32 偏移量,Int32 计数)在 System.IO.StreamReader.ReadBuffer() 在 System.IO.StreamReader.ReadToEnd() 在 Sentry.Extensibility.DefaultRequestPayloadExtractor.DoExtractPayLoad(IHttpRequest 请求)在 Sentry.Extensibility.BaseRequestPayloadExtractor.ExtractPayload(IHttpRequest 请求)在 Sentry.Extensibility.RequestBodyExtractionDispatcher.ExtractPayload(IHttpRequest 请求)在 Sentry.AspNetCore.ScopeExtensions.SetBody(BaseScope 范围、HttpContext 上下文、SentryAspNetCoreOptions 选项)在 Sentry.AspNetCore.ScopeExtensions.Populate(范围范围,HttpContext 上下文,SentryAspNetCoreOptions 选项)在 Sentry.AspNetCore.SentryMiddleware.PopulateScope(HttpContext 上下文, 范围范围)在 Sentry.Scope.Evaluate()
代码隐藏
try
{
string folder = "FileLocation/";
string folderpath = "";
if (model.Filess != null)
{
string fileExtension = Path.GetExtension(model.Filess.FileName);
fileExtension = fileExtension.ToLower();
long fileSize = model.Filess.Length;
if (fileSize <= 10485760)
{
folderpath = Path.Combine(__hostingEnvironment.WebRootPath, "Uploads", folder);
if (!Directory.Exists(folderpath))
{
Directory.CreateDirectory(folderpath);
}
var parsedContentDisposition =
ContentDispositionHeaderValue.Parse(model.Filess.ContentDisposition);
var filename = Path.Combine(__hostingEnvironment.WebRootPath,
"Uploads", folder, parsedContentDisposition.FileName.Trim('"'));
using (var stream = System.IO.File.OpenWrite(filename))
{
await model.Filess.CopyToAsync(stream);
}
}
};
}
catch (Exception ex)
{
}
【问题讨论】:
标签: c# asp.net .net iis asp.net-core