title: How to display Asp.net Identity cookie expire popup in MVC
body: <p>I have MVC 5 web API application which uses Asp.net identity for authentication and Authorization.This is single page application and user can login using email and password.I have to show session expires popup if user idle for some time.</p>
  
  <p>I have tried using Session.Timeout in web.config. It doesn't work because, my application wont refresh. All client communicates server using AJAX.</p>
  
  <p>How can I show session expire pop up based on cookies time out?</p>
  
  <pre><code>    public void ConfigureAuth(IAppBuilder app)
      {
  
          string expireTimeConfig = WebConfigurationManager.AppSettings["ExpireTime"];
          int expireTimeSpan = Convert.ToInt32(expireTimeConfig);
          // Enable the application to use a cookie to store information for the signed in user
          app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              CookieName = "APP",
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
              LoginPath = new PathString("/Account/Login"),
              ExpireTimeSpan = TimeSpan.FromMinutes(expireTimeSpan),
              SlidingExpiration = true,
              Provider = new CookieAuthenticationProvider()
              {
                  //  OnValidateIdentity = MyCustomValidateIdentity, //refer to the implementation below
                  //    OnValidateIdentity = ImpersonatingSecurityStampValidator.OnValidateIdentity&lt;UserManager, User&gt;(
                  //validateInterval: TimeSpan.FromMinutes(10),
                  //regenerateIdentity: (manager, user) =&gt; manager.CreateIdentityAsync(user)),
  
                  OnApplyRedirect = ctx =&gt;
                  {
                      if (!IsApiRequest(ctx.Request))
                      {
                          ctx.Response.Redirect(ctx.RedirectUri);
                      }
                  },
                  OnResponseSignIn = ctx =&gt;
                  {
                      var ticks = ctx.Options.SystemClock.UtcNow.AddHours(10).UtcTicks;
                      ctx.Properties.Dictionary.Add("absolute", ticks.ToString());
                  },
                  OnValidateIdentity = ctx =&gt;
                  {
                      bool reject = true;
                      string value;
                      if (ctx.Properties.Dictionary.TryGetValue("absolute", out value))
                      {
                          long ticks;
                          if (Int64.TryParse(value, out ticks))
                          {
                              reject = ctx.Options.SystemClock.UtcNow.UtcTicks &gt; ticks;
                          }
                      }
  
                      if (reject)
                      {
                          ctx.RejectIdentity();
                          // optionally clear cookie
                          ctx.OwinContext.Authentication.SignOut(ctx.Options.AuthenticationType);
                      }
  
                      return Task.FromResult(0);
                  }
  
              },
  
  
          });
          // Use a cookie to temporarily store information about a user logging in with a third party login provider
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  
  
          if (Convert.ToBoolean(WebConfigurationManager.AppSettings["OAuth"].ToString()))
          {
              // Uncomment the following lines to enable logging in with third party login providers
              app.UseMicrosoftAccountAuthentication(new MicrosoftAccountAuthenticationOptions
              {
                  ClientId = WebConfigurationManager.AppSettings["microsoftClientId"].ToString(),
                  ClientSecret = WebConfigurationManager.AppSettings["microsoftClientSecret"].ToString(),
                  Scope =
              {
                  "wl.basic", "wl.emails"
              }
              });
  
              app.UseTwitterAuthentication(
                 consumerKey: WebConfigurationManager.AppSettings["twitterConsumerKey"].ToString(),
                 consumerSecret: WebConfigurationManager.AppSettings["twitterConsumerSecret"].ToString());
  
              app.UseFacebookAuthentication(new FacebookAuthenticationOptions
              {
                  AppId = WebConfigurationManager.AppSettings["facebookAppId"].ToString(),
                  AppSecret = WebConfigurationManager.AppSettings["facebookAppSecret"].ToString(),
                  Scope = { "email" }
              });
  
              var options = new GoogleOAuth2AuthenticationOptions
              {
                  ClientId = WebConfigurationManager.AppSettings["googleClientId"].ToString(),
                  ClientSecret = WebConfigurationManager.AppSettings["googleClientSecret"].ToString(),
                  Provider = new GoogleOAuth2AuthenticationProvider
                  {
                      OnAuthenticated = async context =&gt;
                      {
                          string accessToken = context.AccessToken;
  
                          // Retrieve the name of the user in Google
                          string googleName = context.Name;
  
                          // Retrieve the user's email address
                          string googleEmailAddress = context.Email;
  
                          // You can even retrieve the full JSON-serialized user
                          var serializedUser = context.User;
                      }
                  }
              };
  
              app.UseGoogleAuthentication(options);
  
              app.UseLinkedInAuthentication(
                  clientId: WebConfigurationManager.AppSettings["linkedInClientId"].ToString(),
                  clientSecret: WebConfigurationManager.AppSettings["linkedInClientSecret"].ToString());
  
              app.UseYahooAuthentication(consumerKey: WebConfigurationManager.AppSettings["yahooConsumerKey"].ToString(),
                  consumerSecret: WebConfigurationManager.AppSettings["yahooConsumerSecret"].ToString());
  
          }
  
          // app.UseKentorAuthServicesAuthentication(CreateAuthServicesOptions( ));
  
          app.MapSignalR();
  
  
      }
  </code></pre>
  
  <p>How can i read ExpireTimeSpan on the client and shows session time out popup?</p>