62,074
社区成员
发帖
与我相关
我的任务
分享
private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
HttpWorkerRequest worker = GetWorkerRequest(app.Context);
uploadKey = app.Context.Request.QueryString["guid"] + "uploadprogress";
contentLengthKey = app.Context.Request.QueryString["guid"] + "uploadlength";
rwl = new ReaderWriterLock();
int bufferSize = (int)app.Application[bufferSizeKey];
//check whether the page is an upload page
if (IsUploadPages())
{
//主要就是从下面开始我不太懂
if (app.Context.Request.ContentLength > 0)
{
TotalSize = app.Context.Request.ContentLength;
MemoryStream mem = new MemoryStream(app.Context.Request.ContentLength);
byte [] data = worker.GetPreloadedEntityBody();
mem.Write(data, 0, data.Length);
int read = 0;
int counter = data.Length;
while (counter < app.Context.Request.ContentLength)
{
if (counter + bufferSize > app.Context.Request.ContentLength)
bufferSize = app.Context.Request.ContentLength - counter;
data = new byte[bufferSize];
CurrentSize = counter;
read = worker.ReadEntityBody(data, bufferSize);
counter += read;
mem.Write(data, 0, bufferSize);
}
mem.Position = 0;
byte [] memData = new byte[mem.Length];
mem.Read(memData, 0, (int)mem.Length);
PushRequestToIIS(worker, memData);
}
}
}