ASP.net uses HttpModule to make modifications to the received parameter values __.net

Source: Internet
Author: User

Configuration method: <add name= "Fileeditmodule" type= "Framework.fileeditmodule, Framework"/>

public class FileEditModule:System.Web.IHttpModule {public void Dispose () {} public void Init (HTT Papplication application) {application.
        BeginRequest + = new EventHandler (application_beginrequest); } public void Application_BeginRequest (object sender, EventArgs e) {HttpContext
            context = HttpContext.Current; HttpRequest request = context.

            Request; if (context.
            Request.httpmethod!= "POST") {return; var file = Request.

            InputStream;

            StreamReader sr = new StreamReader (file); String SourceCode2 = Sr.
            ReadToEnd (); File.

            Seek (0, seekorigin.begin); String sourcecode =..
            Modification method (SOURCECODE2);
            if (Sourcecode.equals (SourceCode2)) {return; } byte[] SourceData = System.Text.Encoding.UTF8.GetBytes (sourcecode); ((System.Web.HttpInputStream) (file)). _data._data//((System.Web.HttpInputStream) (file). _data {System.Web.Ht Tprawuploadedcontent} System.Web.HttpRawUploadedContent BindingFlags bind = BindingFlags.NonPublic | BindingFlags.Instance | Bindingflags.ignorecase |
            Bindingflags.getfield; Assembly Systemweb = Assembly.Load ("system.web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"
            );
            Assembly systemweb = assembly.getassembly (typeof (HttpRequest));
            Type type = Systemweb.gettype ("System.Web.HttpInputStream"); FieldInfo method = Type.
            GetField ("_data", bind); var data = method. GetValue (Request.
            InputStream); var _data = data. GetType ().
            GetField ("_data", bind); var _length = data. GetType ().
            GetField ("_length", bind); var _expectedlength = data. GetType ().
            GetField ("_expectedlength", bind); var _completed = data. GetType (). GetField ("_comPleted ", bind); var _datavalue = _data.
            GetValue (data) as byte[]; _data.
            SetValue (data, sourcedata); _length.
            SetValue (data, sourcedata.length);
            _expectedlength.setvalue (data, sourcedata.length); _completed.
        SetValue (data, true); }
    }


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.