The HTTP module code returned by IIS when the files uploaded by Asp.net are too large-convenient for future use

Source: Internet
Author: User
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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.