asp.net 使用HttpModule对接收到的参数值进行修改

配置方法:

     <httpModules>
      <add name="FileEditModule" type="Framework.FileEditModule, Framework" />

    </httpModules>


public class FileEditModule : System.Web.IHttpModule
    {
        public void Dispose() { }

        public void Init(HttpApplication 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 = ..修改方法(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.HttpRawUploadedContent}	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);
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要捕获m3u8请求,您可以使用ASP.NET中的HttpModuleHttpHandler。HttpModule是一种可重用的类,可拦截和处理请求和响应。HttpHandler是一种可执行文件,可以处理特定类型的请求。 以下是使用HttpModule捕获m3u8请求的示例代码: ```csharp public class M3u8Module : IHttpModule { public void Init(HttpApplication app) { app.BeginRequest += new EventHandler(OnBeginRequest); } private void OnBeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpContext context = app.Context; if (context.Request.Url.AbsolutePath.EndsWith(".m3u8")) { //处理m3u8请求 } } public void Dispose() { } } ``` 在此示例中,您可以在OnBeginRequest方法中检查请求的URL是否以“.m3u8”结尾。如果是,则可以处理请求。 要使用HttpHandler捕获m3u8请求,请创建一个继承自IHttpHandler的类,并实现ProcessRequest方法。然后,在Web.config文件中将处理程序映射到m3u8扩展名。 以下是使用HttpHandler捕获m3u8请求的示例代码: ```csharp public class M3u8Handler : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.Request.Url.AbsolutePath.EndsWith(".m3u8")) { //处理m3u8请求 } } public bool IsReusable { get { return true; } } } ``` 在Web.config文件中添加以下内容: ```xml <system.webServer> <handlers> <add name="M3u8Handler" path="*.m3u8" verb="*" type="YourNamespace.M3u8Handler" /> </handlers> </system.webServer> ``` 使用HttpModuleHttpHandler捕获m3u8请求都可以实现相同的目的。您可以根据您的需要选择其中一种方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值