title: how to exipre cookies in same session id in asp.net core
body: <blockquote>
    <p>What do I miss to clear cookie to logout user .After logout when I click on backward arrow on the browser still my login username and password is saved and I am back to application.Do I need to remove services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    to clear cookie .   </p>
  </blockquote>
  
  <p><strong><em>Logout Method</em></strong></p>
  
  <pre><code>        /// To logout user from Application
          /// &lt;/summary&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
  
          [Obsolete]
          public IActionResult Logout()
          {
              var model = new LoginViewModel();
              HttpContext.Session.Clear();
              HttpContext.Session.Remove(HttpContext.Session.Id);
  
  
              Response.Cookies.Delete(".AspNetCore.Antiforgery.kLmeyaPL6YU");
  
              foreach (var cookie in Request.Cookies.Keys)
              {
                  Response.Cookies.Delete(cookie);
  
              }
  
              var cookies = Request.Cookies.Keys;
              return Redirect("/");
          }```
  
  ***startup.cs***
  ```   public void ConfigureServices(IServiceCollection services )
          {
  
  
              services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                   .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =&gt;
                    {
                       options.LoginPath = new PathString("/Account/Login/");
  
                   });
  
  
              services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
              {
  
                  options.CheckConsentNeeded = context =&gt; true;
                  options.MinimumSameSitePolicy = SameSiteMode.None;
  
              });
           //   var isEmployeeUserPolicy = new AuthorizationPolicyBuilder().RequireRole("Employee").Build();
              /* services.AddMvc(options =&gt;
               {
                   options.Filters.Add(new ApplyPolicyOrAuthorizeFilter(isEmployeeUserPolicy));
               });*/
            //  services.AddSignalR();
  
              services.Configure&lt;LdapConfig&gt;(Configuration.GetSection("ldap"));
  
              services.AddScoped&lt;IAuthenticationService, LdapAuthenticationService&gt;();
              /* services.AddScoped&lt;ECXSecurityAccess.ECXSecurityAccessClient&gt;(provider =&gt; {
  
                   var client = new ECXSecurityAccessClient();
  
                   // Use configuration object to read it from appconfig.json
                   client.ClientCredentials.UserName.UserName = Configuration["MyService:Username"];
                   client.ClientCredentials.UserName.Password = Configuration["MyService:Password"];
                   client.Endpoint.Address = new EndpointAddress(Configuration["MyService:BaseUrl"]);
  
                   return client;
               });
               services.AddAuthentication(IISDefaults.AuthenticationScheme);
               services.Configure&lt;IISOptions&gt;(options =&gt; {
                   options.AutomaticAuthentication = true;
                   options.ForwardClientCertificate = true;
               });*/
              services.AddDistributedMemoryCache();
              services.AddHttpContextAccessor();
              services.AddSession(options =&gt;
              {
                  // Set a short timeout for easy testing.
                  options.IdleTimeout = TimeSpan.FromSeconds(10);
                  options.Cookie.HttpOnly = true;
                  // Make the session cookie essential
                  options.Cookie.IsEssential = true;
              });
  
  
              services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  
              services.Configure&lt;MySetting&gt;(Configuration.GetSection("MySetting"));
              services.AddSingleton(Configuration);
              services.AddSingleton&lt;IActionContextAccessor, ActionContextAccessor&gt;();
              services.AddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();
              services.ToPagerList();
              var MySetting = Configuration.GetSection("MySetting");
  
  
  
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
  
  
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              else
              {
                  app.UseExceptionHandler("/Home/Error");
  
                  app.UseHsts();
              }
  
              app.UseCookiePolicy(new CookiePolicyOptions
              {
                  HttpOnly = HttpOnlyPolicy.Always,
                  Secure = CookieSecurePolicy.Always,
                  MinimumSameSitePolicy = SameSiteMode.None
              });
  
              app.UseAuthentication();
              app.UseHttpsRedirection();
  
              app.UseStaticFiles();
              app.UseStaticFiles(new StaticFileOptions
              {
                  FileProvider = new PhysicalFileProvider(
                 Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")),
                  RequestPath = "/MyImages"
              });
  
              app.UseDirectoryBrowser(new DirectoryBrowserOptions
              {
                  FileProvider = new PhysicalFileProvider(
                      Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")),
                  RequestPath = "/MyImages"
              });
              app.UseMiddleware&lt;StackifyMiddleware.RequestTracerMiddleware&gt;();
              app.UseCookiePolicy();
              app.UseSession();
              app.UseMvc(routes =&gt;
              {
                  routes.MapRoute(
                    name: "Login",
                   template: "{controller=Account}/{action=Login}/{id?}");
  
  
                  routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
              });
  
  
          }
      }```
  </code></pre>