国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
截獲asp.net http輸出流自己做處理,替換html內(nèi)容_站長(zhǎng)域名論壇www.91c...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Reflection;

public partial class _Default : System.Web.UI.Page
{
    StringBuilder content = new StringBuilder();
    TextWriter tw_old, tw_new;
    FieldInfo tw_field;

    protected void Page_Load(object sender, EventArgs e)
    {
        var context = HttpContext.Current;

        tw_old = context.Response.Output;//Response原來(lái)的OutPut
        tw_new = new StringWriter(content);//一個(gè)StringWriter,用來(lái)獲取頁(yè)面內(nèi)容
        var type_rp = context.Response.GetType();
        //通過(guò)反射獲取對(duì)象的私有字段
        tw_field = type_rp.GetField("_writer", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        tw_field.SetValue(context.Response, tw_new);
    }

    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        //替換回Response的OutPut
        tw_field.SetValue(HttpContext.Current.Response, tw_old);
        //做自己的處理
        content.AppendLine("<!--江湖小子-->");
        HttpContext.Current.Response.Write(content.ToString());
    }
}

方法二,用HttpModul來(lái)實(shí)現(xiàn):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Text;
using System.Reflection;

/// <summary>
///HttpModule 的摘要說(shuō)明
/// </summary>
public class HttpModule : IHttpModule
{
    private HttpApplication _contextApplication;
    private TextWriter tw_new, tw_old;
    private StringBuilder _content;
    private FieldInfo tw_field;

    public void Init(HttpApplication context)
    {
        _contextApplication = context;
        _contextApplication.PreRequestHandlerExecute += new EventHandler(_contextApplication_PreRequestHandlerExecute);
    }

    public void Dispose()
    {
        _contextApplication = null;
        _contextApplication.Dispose();
    }

    public void _contextApplication_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpContext context = _contextApplication.Context;

        var _page = context.Handler as System.Web.UI.Page;
        _page.Unload += new EventHandler(_page_Unload);

        _content = new StringBuilder();
        tw_old = context.Response.Output;//Response原來(lái)的OutPut
        tw_new = new StringWriter(_content);//一個(gè)StringWriter,用來(lái)獲取頁(yè)面內(nèi)容
        var type_rp = context.Response.GetType();
        tw_field = type_rp.GetField("_writer", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        tw_field.SetValue(context.Response, tw_new);
    }


    void _page_Unload(object sender, EventArgs e)
    {
        //替換回Response的OutPut
        tw_field.SetValue(HttpContext.Current.Response, tw_old);
        //做自己的處理
        _content.AppendLine("<!--江湖小子-->");
        HttpContext.Current.Response.Write(_content.ToString());
    }

}

方法三:
public class HttpModule : IHttpModule
{
    private HttpApplication _contextApplication;
    private TextWriter tw_new, tw_old;
    private StringBuilder _content;
    private FieldInfo tw_field;

    public void Init(HttpApplication application)
    {
        _contextApplication = application;
        _contextApplication.BeginRequest += new EventHandler(_contextApplication_BeginRequest);
        _contextApplication.EndRequest +=new EventHandler(_contextApplication_EndRequest);
    }

    void _contextApplication_BeginRequest(object sender, EventArgs e)
    {
        _content = new StringBuilder();
        tw_old = _contextApplication.Response.Output;
        tw_new = new StringWriter(_content);
        var type_rp = _contextApplication.Response.GetType();
        tw_field = type_rp.GetField("_writer", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        tw_field.SetValue(_contextApplication.Response, tw_new);
    }

    void _contextApplication_EndRequest(object sender, EventArgs e)
    {
        tw_field.SetValue(_contextApplication.Response, tw_old);
        //做自己的處理
        _content.AppendLine("<!--jhxz-->");
        _contextApplication.Response.Write(_content.ToString());
    }

    public void Dispose()
    {
        _contextApplication = null;
        _contextApplication.Dispose();
    }
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
一般處理程序
.Net 中的反射(動(dòng)態(tài)創(chuàng)建類(lèi)型實(shí)例)
ASP.NET運(yùn)行機(jī)制和圖片盜鏈問(wèn)題
巧用asp.net 過(guò)濾所有的Response請(qǐng)求并替換部分內(nèi)容,徹底解決MVC虛擬路徑問(wèn)題.
可測(cè)試的HttpModule和HttpHandler
c#中從網(wǎng)頁(yè)上gridview導(dǎo)出excel時(shí),如何將excel的列設(shè)置成文本類(lèi)型(即保留...
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服