;

How to Extend/Increase Session Timeout in ASP.NET or ASP.NET MVC c#


Tutorialsrack 02/10/2020 C# ASP.NET MVC

In this article, you will learn how to increase or extend the session timeout in ASP.NET or ASP.NET MVC C#. By default, the session timeout is 20 minutes after that session will expire. So if you want to increase or extend the session custom timeout for an application. You can set it in different ways such as using Web.config, Global.asax file, or using IIS.

Here are some examples to set sessions custom timeout in ASP.NET or ASP.NET MVC.

Example 1: Using the Web.config file

In this example, we will set the session custom timeout to 120 minutes.

Example 1: Using the Web.config file
<configuration>
    <system.web>
        <sessionState mode="InProc" timeout="120"></sessionState>
    </system.web>
</configuration>

Example 2: Using a Global.asax file

In this example, we will set the session custom timeout to 120 minutes inside Session_Starts() event. 

Example 2: Using a Global.asax file
void Session_Start(object sender, EventArgs e) {
  if (Session.IsNewSession) {
    //do things that need to happen
    //when a new session starts.
    Session.Timeout = 120;
  }
}

Example 3: Using IIS

In this example, we will set the session custom timeout whatever timeout value you want. To set the session time, you have to follow these steps as given:

Step 1: Open IIS

Step 2: Select the site for which you want to increase session timeout

Step 3: Now find ASP in the IIS section

Responsive image

Step 4: Now Double Click on ASP and setting option opened, now find session properties in the services section.

Step 5: Now expand the session properties and change the value of the timeout. By default, the timeout value is 20 minutes, now change it to whatever timeout value you want.

Step 6: click on the apply link on the right

Step 7:  Finally check your Application Pool's idle timeout that application pool idle timeout too matches your session timeout,  follow these steps: IIS Manager > Application Pools > DefaultAppPool > Advanced Setting > Process Model > idle timeout in minutes.

I hope this article will help you to understand how to increase or extend the session timeout in ASP.NET or ASP.NET MVC C#.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags