This function is mainly used to avoid impact. ASP. NET To send the normal request content other than the uploaded file content to ASP. NET Page processing.
Through analysisHttprequestObjectGetentirerawcontent ()The method reads data and finds that the method assigns a value to the data when reading the data._ RawcontentAttribute, so we only need to assign the processed dataHttprequestObject_ RawcontentAttribute to send dataASP. NETPage. At the same time, because we have modified the request contentHttprequestOf_ ContentlengthIt should also be rewritten.
Because these attributes are private and cannot be accessed directly, we must use the Reflection Method to assign values to the attributes.CodeAs follows:
Private Void Injecttextparts (httprequest request, Byte [] Textparts)
{
Bindingflags flags1 = Bindingflags. nonpublic | Bindingflags. instance;
Type type1 = Request. GetType ();
Fieldinfo info1 = Type1.getfield ( " _ Rawcontent " , Flags1 );
Fieldinfo info2 = Type1.getfield ( " _ Contentlength " , Flags1 );
If (Info1 ! = Null ) && (Info2 ! = Null ))
{
Assembly web = Assembly. getassembly ( Typeof (Httprequest ));
Type hraw = Web. GetType ( " System. Web. httprawuploadedcontent " );
Object [] Arglist = New Object [ 2 ];
Arglist [ 0 ] = Textparts. Length + 1024 ;
Arglist [ 1 ] = Textparts. length;
Cultureinfo currculture = Cultureinfo. currentculture;
Object Httprawuploadedcontent = Activator. createinstance (hraw,
Bindingflags. nonpublic | Bindingflags. instance,
Null ,
Arglist,
Currculture,
Null );
Type contenttype = Httprawuploadedcontent. GetType ();
Fieldinfo datafield = Contenttype. getfield ( " _ DATA " , Flags1 );
Datafield. setvalue (httprawuploadedcontent, textparts );
Fieldinfo lengthfield = Contenttype. getfield ( " _ Length " , Flags1 );
Lengthfield. setvalue (httprawuploadedcontent, textparts. Length );
Fieldinfo filethresholdfield = Contenttype. getfield ( " _ Filethreshold " , Flags1 );
Filethresholdfield. setvalue (httprawuploadedcontent, textparts. Length + 1024 );
Info1.setvalue (request, httprawuploadedcontent );
Info2.setvalue (request, textparts. Length );
}
}
Here, the code is used Net2.0 Encountered a problem. Because in Net1.1 , Httprequest Of _ Rawcontent Attribute is Byte [] Type, Net2.0 This attribute is changed Httprawuploadedcontent Type object. An error occurred while assigning values. View Httprawuploadedcontent Reflection code, found that the original class is to write too large request content to the disk file. No way. I only assign a value to the instance created for this class. Httprequest Of _ Rawcontent Attribute. Now you can upload files. However, ASP. NET The control values of the page are all lost, and the data is not effectively sent to the page. Hey, here is a technology I just learned. --- Debugging framework source code. Therefore Getentirerawcontent () The method is tracked along the way. Httprawuploadedcontent Object _ Length The property is zero, resulting in Httprequest The object considers that there is no valid data and no data is analyzed. Cause Httprequest Of Params Attributes and Forms The data cannot access the request content. After assigning values to these two data values, haha! Ha! Everything went well. The upload process is complete!
As the net2.0 code is only preliminary, after further testing, I will provide it for you to download after completing this summary.