Что мне не хватает, чтобы очистить команду cook ie для выхода пользователя из системы. После выхода из системы, когда я нажимаю стрелку назад в браузере, мое имя пользователя и пароль сохраняются, и я возвращаюсь в приложение. Мне нужно удалить services.AddAuthentication (CookieAuthenticationDefaults.AuthenticationScheme), чтобы очистить cook ie.
Метод выхода из системы
/// To logout user from Application
/// </summary>
/// <returns></returns>
[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 =>
{
options.LoginPath = new PathString("/Account/Login/");
});
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
// var isEmployeeUserPolicy = new AuthorizationPolicyBuilder().RequireRole("Employee").Build();
/* services.AddMvc(options =>
{
options.Filters.Add(new ApplyPolicyOrAuthorizeFilter(isEmployeeUserPolicy));
});*/
// services.AddSignalR();
services.Configure<LdapConfig>(Configuration.GetSection("ldap"));
services.AddScoped<IAuthenticationService, LdapAuthenticationService>();
/* services.AddScoped<ECXSecurityAccess.ECXSecurityAccessClient>(provider => {
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<IISOptions>(options => {
options.AutomaticAuthentication = true;
options.ForwardClientCertificate = true;
});*/
services.AddDistributedMemoryCache();
services.AddHttpContextAccessor();
services.AddSession(options =>
{
// 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<MySetting>(Configuration.GetSection("MySetting"));
services.AddSingleton(Configuration);
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
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<StackifyMiddleware.RequestTracerMiddleware>();
app.UseCookiePolicy();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "Login",
template: "{controller=Account}/{action=Login}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}```