Asp.net隐藏源码ViewState

基于Asp.net的机制,编译网页时会产生一大段ViewState,下面这段代码会隐藏一大段ViewState源代码,但还是会有一小段,基本能满足我的要求啦。

protected LosFormatter losFormatter = new LosFormatter();

        protected override object LoadPageStateFromPersistenceMedium()
        {
            string key = Request.RawUrl + "__viewstate";

            if (Session[key] != null)
            {
                System.IO.MemoryStream stream = (System.IO.MemoryStream)Session[key];
                stream.Seek(0, System.IO.SeekOrigin.Begin);
                return losFormatter.Deserialize(stream);
            }

            return null;

        }

        protected override void SavePageStateToPersistenceMedium(object viewState)
        {
            string key = Request.RawUrl + "__viewstate";
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            losFormatter.Serialize(stream, viewState);
            stream.Flush();
            Session[key] = stream;

        }

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注