ViewState Compression Using Bzip2 ... Latest Prototype ...

zhaozj2021-02-11  172

Just a first stab at this, uses some classes I used in another project (I'll attribute the compression code later ... I believe I got it from the Sharpziplib stuff - with some modifications - I'll stick the comment headers back in TO Comply with the licensing stuff later - Right now consider it an esample only to compress the viewstate is very Simple:

Using system;

Using system.Web.ui;

Using system.io;

Namespace ViewStateCompression

{

///

/// Summary Description for CompressedVsbasePage.

///

Public class compressedvsbasepage: System.Web.ui.page

{

Private losformatter _formatter = new losformatter ();

Protected Override Void SavepageStatetopistenceMedium (Object ViewState)

{

StringWriter SW = new stringwriter ();

_Formatter.Serialize (SW, viewState);

String outstr = compression.compress (sw.toString ());

Page.RegisterHiddenfield ("__ compressedViewState", outstr);

}

Protected Override Object LoadPagestateFromPersistencemedium ()

{

String vsstring = request.form ["__ compressedViewState];

String Outstr = compressis.Decompress (vsstring);

Return_formatter.deSerialize (Outstr);

}

}

}

To use it, just inherit from this page instead of the normal System.Web.UI.Page Obviously you lose some of the normal Viewstate functions such as encryption -. But these should be easy to slot back in ... I am currently seeing Pretty Large Savings in ViewState Size from Using this - Using Bzip2 Compression - As It's A Piece of Code i Had Lying About ..., please try it out. Any Comments / Suggestions Are, as always, appreciated.

UPDATE (27/05/2004): I've updated the demo project, you can now download this from here Main changes are that it now uses my Compression helper object - this uses the standard SharpZipLib, is a bit more efficient and lets. you switch between all the SharpZipLib compression types very easily My experience has shown that this method is best when you're using objects like DataSets which under.1.1 serialize pretty poorly (as in DataSets really serialize to a form of XML -. which tends to . compress really well) in addition, do not turn on encryption when doing this - the compression is REALLY poor then It's really simple to add encryption back in again -. just do it to the string you get from the Stringwriter after serialization - I ' LL Add AN Example Later (Using Rijndael Is Also Gonna Be More Secure and Much Faster Than 3des). Also, Someone Called 'Mark' Left A Comment with Some Great Performance Figures, Here's The Comment:

转载请注明原文地址:https://www.9cbs.com/read-5342.html

New Post(0)