title: Not able to increase session timeout in ASP.NET Core 2.0
body: <p>I am not able to increase the session timeout in ASP.NET Core 2.0. Session gets expired after every 20 to 30 minutes. When I decrease the time to 1 minutes and debug it it works fine but when it is increased to more more than 30 minutes or hours/days it does not last to specified duration.</p>
  <p>Session is expired after 30 minutes in debug mode as well as from IIS (Hosted after publish).</p>
  <pre><code>options.IdleTimeout = TimeSpan.FromMinutes(180);  
  </code></pre>
  <p>I am using below code in startup.cs file.</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc();
          
          // Adds a default in-memory implementation of IDistributedCache.
          services.AddDistributedMemoryCache();
  
          services.ConfigureApplicationCookie(options =&gt;
          {
              options.Cookie.HttpOnly = true;
              options.Cookie.Expiration = TimeSpan.FromDays(3);
              options.ExpireTimeSpan= TimeSpan.FromDays(3);
              options.SlidingExpiration = true;
          });
  
          services.AddSession(options =&gt;
          {
              // Set a short timeout for easy testing.
              options.IdleTimeout = TimeSpan.FromMinutes(180);                
          });
          services.AddSingleton&lt;IConfiguration&gt;(Configuration);
          
         
          // In production, the Angular files will be served from this directory
          services.AddSpaStaticFiles(configuration =&gt;
          {
              configuration.RootPath = &quot;ClientApp/dist&quot;;
          });
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IConfigurationSettings configurationSettings)
      {
         
          //
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler(&quot;/Home/Error&quot;);
          }
  
          app.UseSession();
          app.UseStaticFiles();
          app.UseSpaStaticFiles();
  
          app.UseExceptionHandler(
           builder =&gt;
           {
               builder.Run(
               async context =&gt;
               {
                   context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                   context.Response.ContentType = &quot;application/json&quot;;
                   var ex = context.Features.Get&lt;IExceptionHandlerFeature&gt;();
                   if (ex != null)
                   {                         
                       if(ex.Error is SessionTimeOutException)
                       {
                           context.Response.StatusCode = 333;
                       }
                       if (ex.Error is UnauthorizedAccessException)
                       {
                           context.Response.StatusCode =999;
                       }
                       var err = JsonConvert.SerializeObject(new Error()
                       {
                           Stacktrace = ex.Error.StackTrace,
                           Message = ex.Error.Message
                       });
                       await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes(err), 0, err.Length).ConfigureAwait(false);
                   }
               });
           });
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: &quot;default&quot;,
                  template: &quot;{controller}/{action=Index}/{id?}&quot;);
          });
  
          app.UseSpa(spa =&gt;
          {
              // To learn more about options for serving an Angular SPA from ASP.NET Core,
              // see https://go.microsoft.com/fwlink/?linkid=864501
  
              spa.Options.SourcePath = &quot;ClientApp&quot;;
  
              if (env.IsDevelopment())
              {
                  spa.UseAngularCliServer(npmScript: &quot;start&quot;);
              }
          });
      }
  </code></pre>