Tuesday, October 6, 2009

Afternoon Session 1: Maintaining State in ASP.NET Applications

A replacement speaker on this one. The original guy had a fall on his yacht. Now given by Miguel Castro, the same guy who gave the presentations I went to yesterday morning, which were both very good.

Afternoon Session 1: Maintaining State in ASP.NET Applications
Miguel Castro

"Everything in the web is a giant hack." The perception of "state" on a web page is just an illusion!

Cache less dependable than application, but scalable. Things will drop out of cache if it gets to large.
GridView is responsible for growing ViewState in a big way! Performance!
What to do?
1. Don't enable in-line editing. It's confusing and grows ViewState.
2. Disable ViewState.
3. Make the db call again. It's faster than you think.
Sliding cache lets things auto renew in cache.
Potential to make a user specific cache by appending a uniquifying key (like session id) to the key name of the cache.
By default, session id is sent in memory cookie to user browser.
Max timeout for session is 24 hours!
Anything in session has to be serializable.
To clear var from session, use Session.Remove(), not setting to blank.
To avoid sticky sessions, can have .NET use a single server for ALL session storage

Can create a class to wrap session vars - which solves some of the problem of loosely typed values and need for mistyping session name - the session var pull is in the getter/setter for the class instead, and the getter/setter can do the casting.
So something like:
AppSession.CurrentEmployeeId = 10;
Getter/Setter for static CurrentEmployeesId prop actually does the push to\pull from session.
^^ This is good stuff. Yet another thing to do...

Can do cookieless sessions in web.config - set cookieless="true" in sessionState section. Note that data goes in the url...which is ugly.
WebFarm session storage - use mode="StateService" and turn on ASP.NET State Service in Services (off by def).

Pretty simple stuff in this session, but a couple nice tips and tricks here and there.

No comments:

Post a Comment