When I was bored, I wrote
When viewstate is not stored to the database
When storing data to a database, you can compare the performance.
As for the page size, we all know that viewstate will be quite large when using some components such as the gridview control.
There are two key values in Web. config, which can be set to decide whether to store them in the database or to compress them.
<Add key = "storeviewstateindb" value = "true"/>
<Add key = "compressviewstate" value = "true"/>
Sharpziplib is used for compression. bzip is used at the beginning, but an error is always reported when compress () is used for decompression. Can only instantiate inputstream outputstream solution, refer to the codeproject. http://www.codeproject.com/KB/dotnet/mscompression.aspx
Code attached:
/Files/beyondjay/viewstatepractise.zip
Reminder: If you want to save the database, you need an SQL job to delete unnecessary viewstates. You can determine the time, such as every 15 minutes or every 1 hour.
Job script is very simple.
Use [MSDB]
Go
/***** Object: job [Delete viewstate] script Date: 01/07/2009 17:13:59 ******/
Begin transaction
Declare @ returncode int
Select @ returncode = 0
/***** Object: jobcategory [Web Assistant] script Date: 01/07/2009 17:13:59 ******/
If not exists (Select name from MSDB. DBO. syscategories where name = n' Web Assistant 'and category_class = 1)
Begin
Exec @ returncode = MSDB. DBO. sp_add_category @ class = n'job', @ type = n'local', @ name = n'web assistant'
If (@ error <> 0 or @ returncode <> 0) goto quitwithrollback
End
Declare @ jobid binary (16)
Exec @ returncode = MSDB. DBO. sp_add_job @ job_name = n'delete viewstate ',
@ Enabled = 1,
@ Policy_level_eventlog = 0,
@ Policy_level_email = 0,
@ Policy_level_netsend = 0,
@ Policy_level_page = 0,
@ Delete_level = 0,
@ Description = n' Delete viewstate for every 6 hours ',
@ Category_name = n' Web Assistant ',
@ Owner_login_name = n 'sa ', @ job_id = @ jobid output
If (@ error <> 0 or @ returncode <> 0) goto quitwithrollback
/***** Object: Step [Delete viewstate] script Date: 01/07/2009 17:13:59 ******/
Exec @ returncode = MSDB. DBO. sp_add_jobstep @ job_id = @ jobid, @ step_name = n'delete viewstate ',
@ Step_id = 1,
@ Cmdexec_success_code = 0,
@ On_success_action = 1,
@ On_success_step_id = 0,
@ On_fail_action = 2,
@ On_fail_step_id = 0,
@ Retry_attempts = 0,
@ Retry_interval = 0,
@ OS _run_priority = 0, @ subsystem = n 'tsql ',
@ Command = n' Delete from [State]
Where datediff (MI, [State]. [createtime], getdate ()> 60 ',
@ Database_name = n' advancedapplicationdesign ',
@ Flags = 0
If (@ error <> 0 or @ returncode <> 0) goto quitwithrollback
Exec @ returncode = MSDB. DBO. sp_update_job @ job_id = @ jobid, @ start_step_id = 1
If (@ error <> 0 or @ returncode <> 0) goto quitwithrollback
Exec @ returncode = MSDB. DBO. sp_add_jobschedule @ job_id = @ jobid, @ name = n'delete viewstate ',
@ Enabled = 1,
@ Freq_type = 4,
@ Freq_interval = 1,
@ Freq_subday_type = 4,
@ Freq_subday_interval = 15,
@ Freq_relative_interval = 0,
@ Freq_recurrence_factor = 0,
@ Active_start_date = 20090107,
@ Active_end_date = 99991231,
@ Active_start_time = 0,
Active_end_time = 235959
If (@ error <> 0 or @ returncode <> 0) goto quitwithrollback
Exec @ returncode = MSDB. DBO. sp_add_jobserver @ job_id = @ jobid, @ SERVER_NAME = n' (local )'
If (@ error <> 0 or @ returncode <> 0) goto quitwithrollback
Commit transaction
Goto endsave
Quitwithrollback:
If (@ trancount> 0) rollback transaction
Endsave:
The performance testing tool is jetbrains dottrace 3.1
The environment is vs2005 and sql2005.