Browse DevX
Sign up for e-mail newsletters from DevX


Client- and Server-side Solutions to Managing State in ASP.NET : Page 10

Whether you are building a traditional Windows application or a Web-based application, state is what an application knows about the user, their current interaction with the application, and other pieces of global information. Get a full assessment of the best techniques for managing state.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Cookieless Sessions
Each one of the session state management techniques, both client-side and server-side, depend on using cookies. If the user has configured their browser not to accept cookies then none of the prior techniques for state management will work. Fortunately the ASP.NET framework includes an option to enable cookieless sessions. A cookieless session enables you to track session state without having to rely on browser cookies.

ASP.NET can support cookieless sessions by passing the user's session ID back to the server in the URL. If you can pass the session ID from page to page you can track the user's activity and session state without using a cookie.

You can enable cookieless sessions by setting the sessionState cookieless option to True.

<sessionState mode="Off" stateConnectionString= "tcpip=" sqlConnectionString="data source=(local); Integrated Security=SSPI" cookieless="true" timeout="20" />

Limitations to Cookieless Sessions
A limitation when using cookieless sessions is that you cannot use absolute URLs when linking between pages on your site. You must code every link relative to the current page. For example, these links will work fine:

<a href="salespage.aspx">Sales page</a> <a href="sales/salespage.aspx">Sales page</a> <a href="../sales/salespage.aspx">Sales page</a>

But the next two links will NOT work with cookieless sessions because clicking on either of them starts a new user session and the existing session values are lost.

<a href="/salespage.aspx">Sales page</a> <a href="http://www.mystore.com/salespage.aspx">Sales page</a>

The Redirect statement exhibits the same limitation. You must use relative path references when you use cookieless sessions.

It's a Wrap!
In this article I discussed the important and sometimes confusing essentials of state management. I explored the basics of state management and you learned about the different techniques available on the client-side (ViewState, query strings, and cookies) as well as on the server-side (application state and session state). I also discussed storing session state information in-process and out-of-process. In-process session state management involves storing session variable information in the same Windows process that ASP.NET is running in while out-of-process stores session state in another Windows service or on another machine completely.

Jim Duffy is founder and president of TakeNote Technologies, an award-winning training and software development company. He has a BS degree in Computer and Information Systems and over 19 years of programming and training experience. He is an energetic trainer, skilled developer, and has been published in leading developer-oriented publications. Jim, a Microsoft MVP award recipient, is a popular speaker at regional user groups and developer conferences. He is also a co-host of Computers 2K4, a call-in radio show on WRBZ (AM 850), 850 The Buzz, in Raleigh, NC. Jim is also the author of TakeNote's popular VFP database auditing product, FoxAudit. In addition to his duties with TakeNote, Jim is also the VP of Sales & Marketing for Red Matrix Technologies, a SQL Server tools vendor who's SQLAudit product adds complete audit trail support for SQL Server databases. Additional information about Jim, TakeNote Technologies, and Red Matrix Technologies can be found at www.takenote.com.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date