首页 新闻 会员 周边 捐助

Render方法执行顺序问题

0
悬赏园豆:50 [待解决问题]

  在页面中定义了一段

<%if()
{
    response.write(...);
}
%>

后台重写render方法,拿到生成的html代码中不包含前台if语句块输出的内容,不明白这是怎么回事,我该如何拿到完整的html代码,请各位大神指点一二。

轻狂の书生的主页 轻狂の书生 | 小虾三级 | 园豆:1042
提问于:2017-03-15 17:54
< >
分享
所有回答(1)
0
 public class ResponseLoggerModule : IHttpModule
    {
        private class ResponseCaptureStream : Stream
        {
            private readonly Stream _streamToCapture;
            private readonly Encoding _responseEncoding;

            private string _streamContent;
            public string StreamContent
            {
                get { return _streamContent; }
                private set
                {
                    _streamContent = value;
                }
            }

            public ResponseCaptureStream(Stream streamToCapture, Encoding responseEncoding)
            {
                _responseEncoding = responseEncoding;
                _streamToCapture = streamToCapture;

            }

            public override bool CanRead
            {
                get { return _streamToCapture.CanRead; }
            }

            public override bool CanSeek
            {
                get { return _streamToCapture.CanSeek; }
            }

            public override bool CanWrite
            {
                get { return _streamToCapture.CanWrite; }
            }

            public override void Flush()
            {
                _streamToCapture.Flush();
            }

            public override long Length
            {
                get { return _streamToCapture.Length; }
            }

            public override long Position
            {
                get
                {
                    return _streamToCapture.Position;
                }
                set
                {
                    _streamToCapture.Position = value;
                }
            }

            public override int Read(byte[] buffer, int offset, int count)
            {
                return _streamToCapture.Read(buffer, offset, count);
            }

            public override long Seek(long offset, SeekOrigin origin)
            {
                return _streamToCapture.Seek(offset, origin);
            }

            public override void SetLength(long value)
            {
                _streamToCapture.SetLength(value);
            }

            public override void Write(byte[] buffer, int offset, int count)
            {
                _streamContent += _responseEncoding.GetString(buffer);
                _streamToCapture.Write(buffer, offset, count);
            }

            public override void Close()
            {
                _streamToCapture.Close();
                base.Close();
            }
        }

        #region IHttpModule Members

        private HttpApplication _context;
        public void Dispose()
        {

        }

        public void Init(HttpApplication context)
        {
            _context = context;

            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
            context.PreSendRequestContent += new EventHandler(context_PreSendRequestContent);
        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            _context.Response.Filter = new ResponseCaptureStream(_context.Response.Filter, _context.Response.ContentEncoding);
        }

        void context_PreSendRequestContent(object sender, EventArgs e)
        {
            ResponseCaptureStream filter = _context.Response.Filter as ResponseCaptureStream;

            if (filter != null)
            {
                string responseText = filter.StreamContent;

                // Logging logic here
                if (_context.Request.Url.ToString().ToLower().IndexOf("PosAPI".ToLower()) > -1)
                {
                    LogHeper.Instant.logApi.Info("url:" + _context.Request.Url + "|contnet:" + responseText);
                }
            }
        }

        #endregion
    }
小眼睛老鼠 | 园豆:2731 (老鸟四级) | 2017-03-22 16:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册