Software⏱️ 3 min read📅 2026-06-03

How to Fix: How to set session timeout in web.config

Configure session timeout in ASP.Net web.config for in-process sessions.

Quick Answer: Yes, your configuration is correct. The element with 'timeout' attribute set to '1' will set the session timeout to 1 minute.

The session timeout issue affects ASP.Net web applications that use in-process sessions, causing frustration when users are unable to maintain their session state due to an expired timeout.

Setting the correct session timeout value is crucial to ensure a seamless user experience. In this guide, we will walk you through the steps to set the session timeout value for an ASP.Net web application using VSTS 2008, .Net 3.5, and C#. We will also explore alternative solutions in case the primary method does not work.

⚠️ Common Causes

  • The primary reason for this issue is that the session timeout value is not correctly set in the web.config file. When the session state times out, the user's session data is lost, causing inconvenience to the user.
  • Another possible cause could be a misconfiguration of the SessionState mode, which can lead to incorrect session behavior.

🚀 How to Resolve This Issue

Setting the session timeout value in the web.config file

  1. Step 1: Open the web.config file located in the root directory of your ASP.Net web application.
  2. Step 2: Locate the system.web section and find the sessionState element.
  3. Step 3: Change the mode attribute from its current value to 'InProc' if it is not already set to this value.
  4. Step 4: Set the timeout attribute to the desired value (in minutes) for the session state.
  5. Step 5: Save the changes to the web.config file and restart your ASP.Net development server or IIS.
  6. Step 6: Verify that the session timeout value has been successfully set by checking the SessionState element in the web.config file.

Alternative solution using a custom session class

  1. Step 1: Create a custom session class that inherits from the System.Web.SessionState.SessionStateClass.
  2. Step 2: Override the GetState and SetState methods to implement your own session timeout logic.
  3. Step 3: Use the custom session class in place of the default SessionState class in your ASP.Net web application.
  4. Step 4: Set the session timeout value using the custom session class's properties or methods.
  5. Step 5: Test your ASP.Net web application with the custom session class to ensure that the correct session timeout value is being applied.

🎯 Final Words

By following these steps, you should be able to set the session timeout value for your ASP.Net web application and prevent session timeouts from occurring. Remember to test your application thoroughly to ensure that the solution works as expected.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions