我编写了一个流媒体视频网址应用程序(.NET Framework 4.0),它使用通用处理程序(.ashx)将文件传输到远程服务器(S3签名URL),然后在html5视频标记中播放处理程序响应。这是主流的s3网址代码:
<div><video width="500px" height="500px" src="http://localhost:62489/Handler.ashx" autoplay="autoplay" controls="controls"></video>
Generic Handler(.ashx)
public void ProcessRequest(HttpContext context)
{
try
{
HttpRequest Request = context.Request;
//Assign S3 URl
string OrginalUrl = "https://s3.amazonaws.com/test/1gb.mp4";
System.Net.HttpWebRequest wreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(OrginalUrl);
wreq.Method = System.Net.WebRequestMethods.Http.Get;
wreq.ReadWriteTimeout = System.Threading.Timeout.Infinite;
wreq.Timeout = System.Threading.Timeout.Infinite;
wreq.KeepAlive = false;
wreq.ProtocolVersion = System.Net.HttpVersion.Version10;
using (System.Net.HttpWebResponse wresp = (System.Net.HttpWebResponse)wreq.GetResponse())
{
using (Stream mystream = wresp.GetResponseStream())
{
using (BinaryReader reader = new BinaryReader(mystream))
{
Int64 length = Convert.ToInt32(wresp.ContentLength);
context.Response.Clear();
context.Response.Buffer = false;
context.Response.BufferOutput = false;
context.Response.AddHeader("Content-Type", "application/octet-stream");
context.Response.AddHeader("Content-Length", length.ToString());
byte[] buffer = new byte[4096];
while (true)
{
int bytesRead = mystream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0) break;
if (context.Response.IsClientConnected)
{
context.Response.OutputStream.Write(buffer, 0, bytesRead);
context.Response.OutputStream.Flush();
}
}
}
}
}
}
catch (Exception e)
{
}
}
我的应用程序适用于所有小文件,但是当我尝试发送更大的文件(1 GB)时出现以下错误。我查看了我的应用程序日志文件,并能够提供以下信息:
Exception :The remote host closed the connection. The error code is 0x800703E3
System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
System.Web.HttpResponse.Flush(Boolean finalFlush)
System.Web.HttpResponse.Flush()
System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
ProcessRequest(HttpContext context) in d:\test\Handler\S3StreamingVideo.ashx.cs:line 60
在我调用request.GetResponse()远程连接关闭后7分钟发生故障。 请帮帮我,如何解决这个问题?
由于