How to extend/increase session time out in MVC using c#

How to extend/increase session time out in MVC using c#

Open the web. config file, then increase the value in minutes by using the time out the attribute of the SessionState element. By default, the session timeout value is 20 minutes. Also in your case, if you are using forms authentication.

<system.web>  
  <compilation debug="true" targetFramework="4.5.2"/>  
  <httpRuntime targetFramework="4.5.2"/>  
  <sessionState mode="InProc" timeout="20">  
  </sessionState>  
</system.web>
<body>  
    <div>   
        <h1> Session Time Extended/Incresse</h1>  
        <br /> Your New Session Time Value Is:  
        @Session.Timeout  
    </div>  
</body>
public class HomeController : Controller  
  {  
      // GET: Home  
      public ActionResult Index()  
      {  
          var chkTimeOut = Session.Timeout;  
          if (chkTimeOut  < 20)  
          {  
              // set new time out to session  
              Session.Timeout = 30;  
               return view("TimeOut");  
          }  
          else  
          {                  
              return view("Demo");  
          }  
      }  
 }

Another way

Increase session timeout in IIS

Steps:

1. Login into your server via Remote desktop.
2. Open IIS.
3. Expend your server.
4. Click on Application pool.
5. Select application pool which is assigned to your user.
6. Click on advance settings.
7. Change timeout value from 5 minute to your required.

 

2021-10-03