Blog Stats
  • Posts - 7
  • Articles - 5
  • Comments - 768
  • Trackbacks - 17

 

Speed up ASP.NET pages

One of the most common problems with web pages is largeness. Sometimes, a lot of data from database, scripts and other can make pages too slow, here I will try to suggest some of the more efficient ways for avoid thi problem. In particular we had a very big page that is composed by several web controls in a wizard, some ajax controls and it is full of data bound controls. In the first release we received a lot of errors because some users of the public module of our system had a very slow connection. The most common error was the terribile:Invalid Viewstate.( :-((( ). This error is one the most hated by ASP.NET developers.

So I decided to resolve the problem and reduce drastically the amount of code in that page.


  1. Remove viewstate from the controls that don't need.

  2. Put ViewState in Session.

You can put viewstate in session if your web page inherits from this base class. This class inherits from System.Web.UI.Page and overrides some routines used during page lifecicle, in particular LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium() for load and save viewstate. In normale pages viewstate is put into code as coded string. Here viewstate is loaded in session into server.


Imports Microsoft.VisualBasic


Namespace EasyCV

Public Class ViewStateSessionPage : Inherits System.Web.UI.Page

''' <summary>

'''

''' </summary>

''' <remarks></remarks>

Protected Overrides Sub InitializeCulture()

MyBase.InitializeCulture()


Dim cultureCode As String =SessionUtils.GetCurrentLangCode()

Dim cinfo As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture(cultureCode)

System.Threading.Thread.CurrentThread.CurrentUICulture=cinfo

System.Threading.Thread.CurrentThread.CurrentCulture = cinfo

End Sub


'Load viewstate

Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object

Return Session("_ViewState")

End Function


'Save viewstate in Session

Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)

Session("_ViewState") = viewState

End Sub


End Class

End Namespace


This is a good solution if your server have a lot of ram or your database server is powerful, because a good option is saving sessions into database server but this solution require a lot of conversations between application and database server.


  1. Use Cache everywhere is possible.

Using caching in ASP.NET is a great way for avoid too slow pages, in particular when you have a lot of databound controls.

Cache in ASP.NET is a statis/shared object, really simple to use. Here you can find a little example about Cache:


Dim lang As String = SessionUtils.GetCurrentLangCode()

Dim dt As System.Collections.Generic.IList(Of EasyCV.Entities.NameValuePair) = CType(Cache(lang+EasyCV.WebLogic.Caching.CachingConstants.DatasetDrivingLicenses), System.Collections.Generic.List(Of EasyCV.Entities.NameValuePair))


If dt Is Nothing Then

'inizializzazione

Dim dal As ICvTypological = EasyCV.WebLogic.DataAccessLayer.DALManager.GetDal(Of ICvTypological)()

dt=dal.GetByTypeId(SessionUtils.GetCurrentClientID, TypologicalConstants.CvDrivingLicense, lang)

''This code add dataset to cache for 2 hours with normal priority

Cache.Add(lang + EasyCV.WebLogic.Caching.CachingConstants.DatasetDrivingLicenses, dt, Nothing, DateTime.Now.AddMinutes(120), Cache.NoSlidingExpiration, CacheItemPriority.Normal, Nothing)

End If


Me.chkPatente.DataSource = dt


Here I put a dataset into session and it will be there for 2 hours, so I will not ask everytime to db for this data. In my situation I must set dataset for every language, so I must control the entry of Cache.


These are some of the ways for speed up your web forms, but there are other ways (ex. Add compression module to your application).

There isn't one solution for every situation but there are solutions and you must choose the right solution for your application. Everything depends by some factors as architecture, avalaibility,scalability,etc.



Feedback

# re: Speed up ASP.NET pages

Gravatar Correctly performed essay writing help will give students a possibility to have A+. Nonetheless, customized research papers creating will utilize some free time. Thence that should be practicable to buy term paper to prevent it. 03/12/2010 23:17 | JannieBriggs

# makeup brushes

Gravatar Hi,Thank you for your good article , You’re obviously an expert in this topic!makeup brush set
13/08/2011 13:48 | makeup brushes

# make up brushes

Gravatar Great loved it, mac brushes will be waiting for your future article. 16/08/2011 08:01 | make up brushes

# make up brushes

Gravatar This is a great looking blog. I have found so many interesting things in your blog especially the discussion. make up brushes From all the remarks in your posts, it appears that this is often a very popular website.mac brushes 09/10/2011 07:29 | make up brushes

# re: Speed up ASP.NET pages

Gravatar at this time there were definitily accounts of someone capturing over the goblet. I’ve considered pics 24/12/2012 12:17 | piumini moncler

Comments have been closed on this topic.
 

 

Copyright © Antonio Radesca