Saya lihat dari blog kita membicarakan mengenai menggunakan "Cache" yang juga tujuan nya untuk mengoptimalkan bandwidth, dan request ke server untuk melakukan job meload data yang biasa nya data itu pun ternyata dalam kurun waktu tertentu masih sama dengan data yang kita telah load sebelumnya.
Di bawah ini saya berikan contoh aplikasi mengkompres Viewstate di mana kita bisa juga menyimpan data di viewstate dan biasanya juga datagrid/gridview sangat besar menggunakan viewstate ini. Saya juga lihat pada saat penggunaan Crystal Report Viewer di Asp.Net saya lihat di aplikasi saya ViewState ini pun cukup besar penggunaan nya.
Oleh karena itu kita bisa melakukan optimasi dengan menggunakan zip compression bawan dari .Net 2.0 atau kita menggunakan library free dari ICSharpCode.SharpZipLib.
Code nya sbb :
1. Class ZipUtil
using System;
using System.IO;
using System.Text;
using Zip = ICSharpCode.SharpZipLib.Zip.Compression;
namespace MyWeb
{
public class ZipUtil
{
public static byte[] Compress(byte[] Bytes)
{
MemoryStream memory = new MemoryStream();
ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream stream =
new ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream(memory,new Zip.Deflater(Zip.Deflater.BEST_COMPRESSION),131072);
stream.Write(Bytes, 0, Bytes.Length);
stream.Close();
return memory.ToArray();
}
public static byte[] Decompress(byte[] Bytes)
{
ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream stream =
new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(new MemoryStream(Bytes));
MemoryStream memory = new MemoryStream();
byte[] writeData = new byte[4096];
int size;
while (true)
{
size = stream.Read(writeData, 0, writeData.Length);
if (size > 0)
{
memory.Write(writeData, 0, size);
}else break;
}
stream.Close();
return memory.ToArray();
}
}
}
2. Class PageViewStateZip
using System;
using System.IO;
using System.Web.UI;
/// <summary>
/// Summary description for PageViewStateZip
/// </summary>
namespace MyWeb
{
public class PageViewStateZip : System.Web.UI.Page
{
protected override object LoadPageStateFromPersistenceMedium()
{
string vstate = this.Request.Form["__VSTATE"];
byte[] bytes = System.Convert.FromBase64String(vstate);
bytes = ZipUtil.Decompress(bytes);
LosFormatter format = new LosFormatter();
return format.Deserialize(System.Convert.ToBase64String(bytes));
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter format = new LosFormatter();
StringWriter writer = new StringWriter();
format.Serialize(writer, viewState);
String viewStateStr = writer.ToString();
byte[] bytes = System.Convert.FromBase64String(viewStateStr);
bytes = ZipUtil.Compress(bytes);
string vStateStr = System.Convert.ToBase64String(bytes);
ClientScript.RegisterHiddenField("__VSTATE", vStateStr);
}
}
}
Setelah kita mempunyai ke-2 Class ini , ubahlah "System.Web.UI.Page" pada web aplikasi kita di inherit ke
class kita yang baru yaitu : PageViewStateZip
Saya dapatkan info ini dari : http://www.hanselman.com/blog/ZippingCompressingViewStateInASPNET.aspx,
If you want to upgrade from WSS 2.0 to WSS 3.0 and got the error something like : Failed to initialize SharePoint Products and Technologies upgrade.An exception of type Microsoft.SharePoint.PostSetupConfiguration.PostSetupConfigurationTaskException was thrown. Additional exception information: The pre-upgrade scan tool has not yet been run on all servers in the farm.
We have to run the pre-upgrade tool manually and then run the SharePoint Products and Technologies Configuration Wizard to completed upgrade process.
if you get this problem, you can do step following like this :
1. Open a cmd prompt
2. Type cd c:\program files\common files\microsoft shared\web server extensions\12\bin
3. Now type prescan.exe /c preupgradescanconfig.xml /all and press enter
4. Now when it completes it will give you a log file to review for errors. Assuming you have no errors you can move to the next step. If you do have errors then deal with them.
5. Run SharePoint Products and Technologies Configuration Wizard again
Now I am succeed to migrate, but still have a lot of homework to check custom page is work as usual.
This following step i took from link :
http://msmvps.com/blogs/shane/archive/2006/06/07/upgrade-error-and-prescan-exe.aspx