Public class uploadhttpmodule: ihttpmodule
{
// Methods
Private void application_beginrequest (Object sender, eventargs E)
{
Httprequest request = httpcontext. Current. request;
If (request. contentlength> 0x400000)
{
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)
{
Written ED = buffer. length;
}
Int totalrecv = received;
If (! Wr. isentireentitybodyispreloaded ())
{
Buffer = new byte [0 xFFFF];
While (contentlen-totalrecv)> = received)
{
Written ED = Wr. readentitybody (buffer, buffer. Length );
Totalrecv + = received;
}
Written ED = Wr. readentitybody (buffer, contentlen-totalrecv );
}
}
Context. response. Redirect ("error. aspx" + request. url. query + "");
}
Catch (exception)
{
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 );
}
}