viewstateMoverModule.cs :  » Content-Management-Systems-CMS » umbraco » presentation » umbracoBase » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » umbraco 
umbraco » presentation » umbracoBase » viewstateMoverModule.cs
#region Using

using System;
using System.IO;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;

#endregion

namespace umbraco.presentation{

    /// <summary>
    /// Moved the viewstate
    /// </summary>
    public class viewstateMoverModule : IHttpModule
    {
        #region IHttpModule Members

        void IHttpModule.Dispose()
        {
            // Nothing to dispose; 
        }

        void IHttpModule.Init(HttpApplication context)
        {
            if (UmbracoSettings.UseViewstateMoverModule)
            {
                context.BeginRequest += new EventHandler(context_BeginRequest);
            }
        }

        #endregion

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;
            if (app.Request.Url.OriginalString.Contains(".aspx"))
            {
                app.Response.Filter = new ViewstateFilter(app.Response.Filter);
            }
        }

        #region Stream filter

        private class ViewstateFilter : Stream
        {

            public ViewstateFilter(Stream sink)
            {
                _sink = sink;
            }

            private Stream _sink;

            //private Hashtable _html = new Hashtable(); 
            private string html = string.Empty;

            #region Properites

            public override bool CanRead
            {
                get { return true; }
            }

            public override bool CanSeek
            {
                get { return true; }
            }

            public override bool CanWrite
            {
                get { return true; }
            }

            public override void Flush()
            {
                doit();
                _sink.Flush();
            }

            public override long Length
            {
                get { return 0; }
            }

            private long _position;
            public override long Position
            {
                get { return _position; }
                set { _position = value; }
            }

            #endregion

            #region Methods

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

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

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

            public override void Close()
            {
                _sink.Close();
            }

            public override void Write(byte[] buffer, int offset, int count)
            {
                byte[] data = new byte[count];
                Buffer.BlockCopy(buffer, offset, data, 0, count);
                //string html = System.Text.Encoding.Default.GetString(buffer);
                html += System.Text.Encoding.Default.GetString(buffer);
            }
            private void doit()
            {
                int startPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
                if (startPoint >= 0)
                {
                    int endPoint = html.IndexOf("/>", startPoint) + 2;
                    string viewstateInput = html.Substring(startPoint, endPoint - startPoint);
                    int formEndStart = html.IndexOf("</form>");
                    if (formEndStart >= 0)
                    {
                        html = html.Remove(startPoint, endPoint - startPoint);
                        html = html.Insert(formEndStart - (endPoint - startPoint), viewstateInput);
                    }
                }

                byte[] outdata = System.Text.Encoding.Default.GetBytes(html);
                _sink.Write(outdata, 0, outdata.GetLength(0));
            }

            #endregion

        }

        #endregion
    }

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.