Use Session State

Problem

You want to create a Web service that can store information in user-specific session state.

Solution

Avoid this option if possible because it leads to several complications. If it’s absolutely necessary to use session state, set the EnableSession property of the WebMethod attribute to True, and initialize the CookieContainer property of the proxy class before calling the Web method.

Discussion

ASP.NET Web services can use session state to store objects in server-side memory. However, this approach has several consequences, including:

  • Because session state must be tracked using a cookie with the session ID, the client must take additional steps to maintain the cookie. In addition, session state won’t work over protocols other ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.