How to enable Session State in the WebForms application


#1

You can optimize performance for large web forms by configuring the WebForms application to use ASP.NET Session State instead of View State.

While a form will always have a View State hidden input, enabling Session State can reduce the amount of data transferred by the server to the client browser by nearly half, which can significantly improve performance when the server is on a slow network connection and the form’s postbacks are performing poorly.

The drawback to this is that a user’s session might eventually timeout, and enabling Session State might require slightly more memory resources depending on the number of connected users.

Notes

  • Whenever you use Session State instead of View State, a session might eventually timeout after a period of inactivity, which will result in the loss of all changes made since the last save or submit if the user has left an active form open on their computer. By default, session timeout is set to 20 minutes, but this can be increased by adding a <sessionState timeout="" /> node under <system.web> in the web.config file, with the timeout value in minutes (for example, <sessionState timeout="30" /> will increase the timeout to 30 minutes).

  • The procedure to enable Session State and the parameters to use might vary depending on your WorkflowGen configuration. The instructions below are intended for a simple WorkflowGen installation. For an advanced WorkflowGen configuration in a Web Farm or behind a Load Balancer, see https://msdn.microsoft.com/en-us/library/ms178586.aspx for more information on Session State. You can also configure the Web Farm to use sticky sessions; see http://stackoverflow.com/questions/10494431/sticky-and-non-sticky-sessions for more information.

  • For other ways to improve web form performance, see the Performance optimization for large web forms topic.

How to enable Session State

  1. Add a new web.config file or edit the existing one in the \wfgen\WfApps\WebForms folder with the following content:

    <?xml version="1.0"?>
    <configuration>
        <system.web>
            <pages enableSessionState="true" />
        </system.web>
    </configuration>
    
  2. Add the following .NET code to each form for which you want to enable Session State:

    protected override PageStatePersister PageStatePersister
    {
        get
        {
            return new SessionPageStatePersister(Page);
        }
    }
    
    protected override void OnPreLoad(EventArgs e)
    {
        IsSessionLess = false;
        base.OnPreLoad(e);
    }
    

WorkflowGen 7.x Upgrade and enableSessionState