You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.8 KiB
65 lines
2.8 KiB
using System;
|
|
using System.Web;
|
|
using System.Reflection;
|
|
using System.Web.Configuration;
|
|
|
|
namespace OT.Web.Ap_Code
|
|
{
|
|
public class UpLoadHttpModule : IHttpModule
|
|
{
|
|
private void Application_BeginRequest(object sender, EventArgs e)
|
|
{
|
|
HttpRequest request = HttpContext.Current.Request;//0x400000
|
|
HttpRuntimeSection configSection = (HttpRuntimeSection)HttpContext.Current.GetSection("system.web/httpRuntime");
|
|
//if (request.ContentLength > configSection.MaxRequestLength * 1024 || request.ContentLength > BasePage.gintUploadSize * 1024 * 1024)
|
|
if (request.ContentLength > configSection.MaxRequestLength * 1024)
|
|
{
|
|
HttpApplication app = sender as HttpApplication;
|
|
HttpContext context = app.Context;
|
|
try
|
|
{
|
|
HttpWorkerRequest wr = (HttpWorkerRequest)context.GetType().GetProperty("WorkerRequest", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(context, null);
|
|
if (wr.HasEntityBody())
|
|
{
|
|
int contentlen = Convert.ToInt32(wr.GetKnownRequestHeader(11));
|
|
byte[] buffer = wr.GetPreloadedEntityBody();
|
|
int received = 0;
|
|
if (buffer != null)
|
|
{
|
|
received = buffer.Length;
|
|
}
|
|
int totalrecv = received;
|
|
if (!wr.IsEntireEntityBodyIsPreloaded())
|
|
{
|
|
buffer = new byte[0xffff];
|
|
while ((contentlen - totalrecv) >= received)
|
|
{
|
|
received = wr.ReadEntityBody(buffer, buffer.Length);
|
|
totalrecv += received;
|
|
}
|
|
received = wr.ReadEntityBody(buffer, contentlen - totalrecv);
|
|
}
|
|
}
|
|
context.Response.Redirect(request.Url.ToString() + "&ErrMsg=FileMaxError");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
context.Response.Redirect(request.Url.ToString() + "&ErrMsg=FileMaxError");
|
|
context.Response.Redirect("~/Error.aspx" + request.Url.Query + "");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void application_EndRequest(object sender, EventArgs e)
|
|
{
|
|
}
|
|
public void Dispose()
|
|
{
|
|
}
|
|
public void Init(HttpApplication application)
|
|
{
|
|
application.BeginRequest += new EventHandler(this.Application_BeginRequest);
|
|
application.EndRequest += new EventHandler(this.application_EndRequest);
|
|
}
|
|
}
|
|
}
|