Buiding ASP.NET application without Session State?
I just finished watching Stefan Schackow's PDC 2009 session and he mentioned that he is surprised that people are still using Session State in ASP.NET. Session State is even used internally in ASP.NET MVC.
Having worked with a legacy application where everything is put into a "in-proc" se开发者_JAVA百科ssion (even datatables!), I've seen session abuse first-hand.
Is there a way to build an ASP.NET application without session state? How would you store information for each step of a typical e-commerce workflow?
You've got the following options: cookies, database, querystring, page variables, and server cache to try to handle the stateless nature of the web. Each has its own tradeoff, but pragmatically speaking I currently use session that gets stored in the db. This scales well for server farms, helps to keep your pagesize small, and is easy to implement.
I haven't used a session in years. If you need to track a user's progress between pages (say, through a cart checkout process), store whatever state information you require in a database and relate it back to the user with a cookie.
It's worth noting that .NET supports different "session" mechanisms, one of which stores the information in a database (much preferred in my opinion) instead of in-proc.
Check out ASP.NET Membership Profiles. It allows you to serialize and store/retrieve objects per user account, regardless of whether the user is anonymous or not. I've been able to use this successfully with lengthy wizard-type online applications.
精彩评论