当前位置: 代码迷 >> ASP.NET >> aspx页面获取自身要输出的html源代码,该如何解决
  详细解决方案

aspx页面获取自身要输出的html源代码,该如何解决

热度:5495   发布时间:2013-02-25 00:00:00.0
aspx页面获取自身要输出的html源代码
如题,以前有看过别人写的一个方法,现在找不着了,在网上搜索都是获取指定url的源码。

------解决方案--------------------------------------------------------
大湿 我猜他不是这个意思

这样是对的
C# code
public class MyHttpModule : IHttpModule{private HttpApplication _contextApplication;    private TextWriter tw_new, tw_old;    private StringBuilder _content;    private FieldInfo fileinfo;    public void Dispose()    {        _contextApplication = null;        _contextApplication.Dispose();    }    public void Init(HttpApplication context)    {        _contextApplication = context;        _contextApplication.PreRequestHandlerExecute += new EventHandler(_contextApplication_PreRequestHandlerExecute);    }    private void _contextApplication_PreRequestHandlerExecute(object sender, EventArgs e)    {        HttpContext context = _contextApplication.Context;        Page _page = context.Handler as Page;        _page.Unload += new EventHandler(_page_Unload);        _content = new StringBuilder();        tw_old = context.Response.Output;//Response原来的OutPut        tw_new = new StringWriter(_content);        Type type_rp = context.Response.GetType();        fileinfo = type_rp.GetField("_writer", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);        fileinfo.SetValue(context.Response, tw_new);    }    void _page_Unload(object sender, EventArgs e)    {        fileinfo.SetValue(HttpContext.Current.Response, tw_old);        _content.AppendLine("胡学成2B");        HttpContext.Current.Response.Write(_content.ToString());    }
  相关解决方案