ASP.NET Core 2.2 - Is it possible to use cookie authentication when browser (IE11 and Edge) has cookies disabled?ASP.NET MVC Registration create Claim on E-mailWhen is ASP.NET Core 1.0 (ASP.NET 5 / vNext) scheduled for release?Token Based Authentication in ASP.NET CoreMVC External login - How to skip association formI cant get this form to send email or redirect to the correct viewHow to retrieving information without using primary key asp.net c#?Cookie Authentication ASP.NET CoreCan authentication cookie be shared between two .Net Core 2.0 applications?asp.net core 2.2 response cache not work on browserASP.NET Core 2.2 - ProblemDetails
What does it mean to have a subnet mask /32?
Mathematical uses of string theory
Efficiently pathfinding many flocking enemies around obstacles
Why don't electrons take the shorter path in coils?
Would this system work to purify water?
How to draw a cube that can be inscribed within a right circular cone?
Defense against attacks using dictionaries
Can pay be witheld for hours cleaning up after closing time?
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
What is the appropriate benchmark for a Long/Short VIX futures strategy?
How would one country purchase another?
What magic extends life or grants immortality?
What does どうかと思う mean?
How to use "Du hast/ Du hattest'?
Is "The life is beautiful" incorrect or just very non-idiomatic?
If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?
Notepad++ - How to find multiple values on the same line in any permutation
Is using a hyperlink to close a modal a poor design decision?
Singleton Design Pattern implementation in a not traditional way
Using `With[...]` with a list specification as a variable
Avoiding racist tropes in fantasy
Why were the crew so desperate to catch Truman and return him to Seahaven?
Why do all fields in a QFT transform like *irreducible* representations of some group?
Fancy String Replace
ASP.NET Core 2.2 - Is it possible to use cookie authentication when browser (IE11 and Edge) has cookies disabled?
ASP.NET MVC Registration create Claim on E-mailWhen is ASP.NET Core 1.0 (ASP.NET 5 / vNext) scheduled for release?Token Based Authentication in ASP.NET CoreMVC External login - How to skip association formI cant get this form to send email or redirect to the correct viewHow to retrieving information without using primary key asp.net c#?Cookie Authentication ASP.NET CoreCan authentication cookie be shared between two .Net Core 2.0 applications?asp.net core 2.2 response cache not work on browserASP.NET Core 2.2 - ProblemDetails
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm finding that I can, so I must be confused about cookies.
********** SETUP SECTION **********
I've done the following:
- Visual Studio 2017: File -> New Project -> ASP.NET Core Web Application -> Web Application (Model-View-Controller). All defaults (so No Authentication, and Configure for HTTPS checked true). Solution Explorer will look like this:

In Startup.cs, I modified ConfigureServices:
public void ConfigureServices(IServiceCollection services)
// THIS WAS COMMENTED OUT
//services.Configure<CookiePolicyOptions>(options =>
//
// // This lambda determines whether user consent for non-essential cookies is needed for a given request.
// options.CheckConsentNeeded = context => true;
// options.MinimumSameSitePolicy = SameSiteMode.None;
//);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// THIS WAS ADDED
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = false;
options.ExpireTimeSpan = TimeSpan.FromSeconds(20);
);In Startup.cs, I modified Configure:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
// THIS WAS COMMENTED OUT
//app.UseCookiePolicy();
// THIS WAS ADDED
app.UseAuthentication();
app.UseMvc(routes =>
routes.MapRoute(
name: "default",
template: "controller=Home/action=Index/id?");
);In the class for the HomeController.cs that's created for you, I added an [Authorize] tag:
[Authorize]
public class HomeController : Controller
{I added a new class file to the Models folder called AccountModel.cs, this is what it looks like:
namespace WebApplication1.Models
public class LoginViewModel
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email get; set;
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password get; set;
[Display(Name = "Remember me?")]
public bool RememberMe get; set;
I created a New folder called Data and added a new class file called ApplicationUser.cs:
namespace WebApplication1.Data
public class ApplicationUser
public string Email get; set;
public string FullName get; set;
I added a new class file to the Controllers folder called AccountControleler.cs, this is what it looks like:
namespace WebApplication1.Controllers
public class AccountController : Controller
public IActionResult Login()
return View();
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
if (!ModelState.IsValid)
return View(model);
ApplicationUser appUser = await AuthenticateUser(model.Email, model.Password);
if (appUser == null)
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
List<Claim> claims = new List<Claim>
new Claim(ClaimTypes.Name, appUser.FullName),
new Claim("FullName", appUser.FullName),
new Claim(ClaimTypes.Email, appUser.Email),
new Claim(ClaimTypes.Role, "Administrator")
;
ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
AuthenticationProperties authProperties = new AuthenticationProperties();
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
return RedirectToLocal(returnUrl);
private async Task<ApplicationUser> AuthenticateUser(string email, string password)
await Task.Delay(500);
if (email == "so@test.com")
return new ApplicationUser()
Email = "so@test.com",
FullName = "Stack Overflow"
;
else
return null;
private ActionResult RedirectToLocal(string returnUrl)
if (Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
return RedirectToAction("Index", "Home");
I created a New folder under the Views folder called Account and added a new class view called Login.cshtml:
@model WebApplication1.Models.LoginViewModel
@
ViewData["Title"] = "Login";
<h2 class="text-primary">@ViewBag.Title</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@*https://dustinewers.com/how-to-build-html-helpers-like-html-beginform-in-asp-net-mvc/*@
@*https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.ihtmlhelper.beginform?view=aspnetcore-2.2*@
@*@Html.BeginForm("Login", "Account",TModel-routeValues,FormMethod.Post, bool?-AntiforgeryExtensions, TModel-htmlAttributes)*@
@using (Html.BeginForm("Login", "Account", new ReturnUrl = ViewBag.ReturnUrl , FormMethod.Post, null, new @class = "form-horizontal", role = "form" ))
@Html.AntiForgeryToken()
<h4 class="text-primary">Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="form-group">
@Html.LabelFor(m => m.Email, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Email, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Password, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default btn-primary" />
</div>
</div>
<p>
@Html.ActionLink("Register as a new user", "Register")
</p>
@* Enable this once you have account confirmation enabled for password reset functionality
<p>
@Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>*@
</section>
</div>
</div>This is my browser settings (IE11) for cookies:

********** HERE IS WHAT IT LOOKS LIKE WHEN I RUN THE APP **********
Based on what I have set-up, when I run the app, it will take me to the Login Page and I can't get to any of the Home, or Privacy Views until I login. This works. That's not the issue.
I wanted to see what happened if I disabled cookies on the browser. I know I disabled cookies correctly because if I try to log-in to facebook I will get the message "cookies required". Yet, I can run my little test app to my hearts content and it will log me in, expire after 20 seconds (which would force me to log back in once I click a link), etc. No loss of functionality, it works.
- When I first run the app with cookies disabled:

- Then, I log-in using my so@test.com user (type any password):

... And I can navigate to any view I want.
So what am I missing here? Does cookie auth mean something different than the cookies associated with your browser? Or this is some type of server cookie (vs a client cookie or something)? Or does ASP.NET Core figure out a way around that in some way?
********** NEW INFORMATION **********
Looks like I should have tried another browser other than IE. Firefox and Chrome did as expected, whereas IE and Edge ignores the fact that I have its cookies blocked. Does anyone know why? Is this some special magic for Microsoft browsers that other browsers don't have/get?
c# asp.net-core cookies asp.net-core-2.2
|
show 3 more comments
I'm finding that I can, so I must be confused about cookies.
********** SETUP SECTION **********
I've done the following:
- Visual Studio 2017: File -> New Project -> ASP.NET Core Web Application -> Web Application (Model-View-Controller). All defaults (so No Authentication, and Configure for HTTPS checked true). Solution Explorer will look like this:

In Startup.cs, I modified ConfigureServices:
public void ConfigureServices(IServiceCollection services)
// THIS WAS COMMENTED OUT
//services.Configure<CookiePolicyOptions>(options =>
//
// // This lambda determines whether user consent for non-essential cookies is needed for a given request.
// options.CheckConsentNeeded = context => true;
// options.MinimumSameSitePolicy = SameSiteMode.None;
//);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// THIS WAS ADDED
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = false;
options.ExpireTimeSpan = TimeSpan.FromSeconds(20);
);In Startup.cs, I modified Configure:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
// THIS WAS COMMENTED OUT
//app.UseCookiePolicy();
// THIS WAS ADDED
app.UseAuthentication();
app.UseMvc(routes =>
routes.MapRoute(
name: "default",
template: "controller=Home/action=Index/id?");
);In the class for the HomeController.cs that's created for you, I added an [Authorize] tag:
[Authorize]
public class HomeController : Controller
{I added a new class file to the Models folder called AccountModel.cs, this is what it looks like:
namespace WebApplication1.Models
public class LoginViewModel
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email get; set;
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password get; set;
[Display(Name = "Remember me?")]
public bool RememberMe get; set;
I created a New folder called Data and added a new class file called ApplicationUser.cs:
namespace WebApplication1.Data
public class ApplicationUser
public string Email get; set;
public string FullName get; set;
I added a new class file to the Controllers folder called AccountControleler.cs, this is what it looks like:
namespace WebApplication1.Controllers
public class AccountController : Controller
public IActionResult Login()
return View();
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
if (!ModelState.IsValid)
return View(model);
ApplicationUser appUser = await AuthenticateUser(model.Email, model.Password);
if (appUser == null)
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
List<Claim> claims = new List<Claim>
new Claim(ClaimTypes.Name, appUser.FullName),
new Claim("FullName", appUser.FullName),
new Claim(ClaimTypes.Email, appUser.Email),
new Claim(ClaimTypes.Role, "Administrator")
;
ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
AuthenticationProperties authProperties = new AuthenticationProperties();
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
return RedirectToLocal(returnUrl);
private async Task<ApplicationUser> AuthenticateUser(string email, string password)
await Task.Delay(500);
if (email == "so@test.com")
return new ApplicationUser()
Email = "so@test.com",
FullName = "Stack Overflow"
;
else
return null;
private ActionResult RedirectToLocal(string returnUrl)
if (Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
return RedirectToAction("Index", "Home");
I created a New folder under the Views folder called Account and added a new class view called Login.cshtml:
@model WebApplication1.Models.LoginViewModel
@
ViewData["Title"] = "Login";
<h2 class="text-primary">@ViewBag.Title</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@*https://dustinewers.com/how-to-build-html-helpers-like-html-beginform-in-asp-net-mvc/*@
@*https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.ihtmlhelper.beginform?view=aspnetcore-2.2*@
@*@Html.BeginForm("Login", "Account",TModel-routeValues,FormMethod.Post, bool?-AntiforgeryExtensions, TModel-htmlAttributes)*@
@using (Html.BeginForm("Login", "Account", new ReturnUrl = ViewBag.ReturnUrl , FormMethod.Post, null, new @class = "form-horizontal", role = "form" ))
@Html.AntiForgeryToken()
<h4 class="text-primary">Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="form-group">
@Html.LabelFor(m => m.Email, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Email, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Password, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default btn-primary" />
</div>
</div>
<p>
@Html.ActionLink("Register as a new user", "Register")
</p>
@* Enable this once you have account confirmation enabled for password reset functionality
<p>
@Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>*@
</section>
</div>
</div>This is my browser settings (IE11) for cookies:

********** HERE IS WHAT IT LOOKS LIKE WHEN I RUN THE APP **********
Based on what I have set-up, when I run the app, it will take me to the Login Page and I can't get to any of the Home, or Privacy Views until I login. This works. That's not the issue.
I wanted to see what happened if I disabled cookies on the browser. I know I disabled cookies correctly because if I try to log-in to facebook I will get the message "cookies required". Yet, I can run my little test app to my hearts content and it will log me in, expire after 20 seconds (which would force me to log back in once I click a link), etc. No loss of functionality, it works.
- When I first run the app with cookies disabled:

- Then, I log-in using my so@test.com user (type any password):

... And I can navigate to any view I want.
So what am I missing here? Does cookie auth mean something different than the cookies associated with your browser? Or this is some type of server cookie (vs a client cookie or something)? Or does ASP.NET Core figure out a way around that in some way?
********** NEW INFORMATION **********
Looks like I should have tried another browser other than IE. Firefox and Chrome did as expected, whereas IE and Edge ignores the fact that I have its cookies blocked. Does anyone know why? Is this some special magic for Microsoft browsers that other browsers don't have/get?
c# asp.net-core cookies asp.net-core-2.2
Is there any demo to reproduce your issue? I made a test with your steps, it works correctly when the cookies is disabled and the request will be redirect to the Account controller all the time. Check web browser network tab to see whether there is any cookies in the request and reponse.
– Tao Zhou
Mar 27 at 2:22
Just to clarify, at the very start, mine is always routed to the Account controller until I actually sign-in (my controller does actually perform await HttpContext.SignInAsync - oh, and I do have a Model class, as well). Once I sign-in, I'm able to see any of the Contact, Home, or About pages. All while my browser has cookies disabled
– JustLooking
Mar 27 at 15:57
I really should have tried another browser besides IE11, I suppose. Chrome and Firefox both do what you describe, keep redirecting to the Account controller. Whereas IE11 ignores the fact that my settings are to block all cookies.
– JustLooking
Mar 27 at 17:55
Edge too. So Microsoft browsers work, even when cookies are blocked. But other browsers don't (Firefox and Chrome)
– JustLooking
Mar 27 at 18:03
Fail to reproduce your issue withIE 11 Version 11.55.17763.0
– Tao Zhou
Mar 28 at 5:34
|
show 3 more comments
I'm finding that I can, so I must be confused about cookies.
********** SETUP SECTION **********
I've done the following:
- Visual Studio 2017: File -> New Project -> ASP.NET Core Web Application -> Web Application (Model-View-Controller). All defaults (so No Authentication, and Configure for HTTPS checked true). Solution Explorer will look like this:

In Startup.cs, I modified ConfigureServices:
public void ConfigureServices(IServiceCollection services)
// THIS WAS COMMENTED OUT
//services.Configure<CookiePolicyOptions>(options =>
//
// // This lambda determines whether user consent for non-essential cookies is needed for a given request.
// options.CheckConsentNeeded = context => true;
// options.MinimumSameSitePolicy = SameSiteMode.None;
//);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// THIS WAS ADDED
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = false;
options.ExpireTimeSpan = TimeSpan.FromSeconds(20);
);In Startup.cs, I modified Configure:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
// THIS WAS COMMENTED OUT
//app.UseCookiePolicy();
// THIS WAS ADDED
app.UseAuthentication();
app.UseMvc(routes =>
routes.MapRoute(
name: "default",
template: "controller=Home/action=Index/id?");
);In the class for the HomeController.cs that's created for you, I added an [Authorize] tag:
[Authorize]
public class HomeController : Controller
{I added a new class file to the Models folder called AccountModel.cs, this is what it looks like:
namespace WebApplication1.Models
public class LoginViewModel
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email get; set;
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password get; set;
[Display(Name = "Remember me?")]
public bool RememberMe get; set;
I created a New folder called Data and added a new class file called ApplicationUser.cs:
namespace WebApplication1.Data
public class ApplicationUser
public string Email get; set;
public string FullName get; set;
I added a new class file to the Controllers folder called AccountControleler.cs, this is what it looks like:
namespace WebApplication1.Controllers
public class AccountController : Controller
public IActionResult Login()
return View();
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
if (!ModelState.IsValid)
return View(model);
ApplicationUser appUser = await AuthenticateUser(model.Email, model.Password);
if (appUser == null)
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
List<Claim> claims = new List<Claim>
new Claim(ClaimTypes.Name, appUser.FullName),
new Claim("FullName", appUser.FullName),
new Claim(ClaimTypes.Email, appUser.Email),
new Claim(ClaimTypes.Role, "Administrator")
;
ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
AuthenticationProperties authProperties = new AuthenticationProperties();
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
return RedirectToLocal(returnUrl);
private async Task<ApplicationUser> AuthenticateUser(string email, string password)
await Task.Delay(500);
if (email == "so@test.com")
return new ApplicationUser()
Email = "so@test.com",
FullName = "Stack Overflow"
;
else
return null;
private ActionResult RedirectToLocal(string returnUrl)
if (Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
return RedirectToAction("Index", "Home");
I created a New folder under the Views folder called Account and added a new class view called Login.cshtml:
@model WebApplication1.Models.LoginViewModel
@
ViewData["Title"] = "Login";
<h2 class="text-primary">@ViewBag.Title</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@*https://dustinewers.com/how-to-build-html-helpers-like-html-beginform-in-asp-net-mvc/*@
@*https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.ihtmlhelper.beginform?view=aspnetcore-2.2*@
@*@Html.BeginForm("Login", "Account",TModel-routeValues,FormMethod.Post, bool?-AntiforgeryExtensions, TModel-htmlAttributes)*@
@using (Html.BeginForm("Login", "Account", new ReturnUrl = ViewBag.ReturnUrl , FormMethod.Post, null, new @class = "form-horizontal", role = "form" ))
@Html.AntiForgeryToken()
<h4 class="text-primary">Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="form-group">
@Html.LabelFor(m => m.Email, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Email, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Password, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default btn-primary" />
</div>
</div>
<p>
@Html.ActionLink("Register as a new user", "Register")
</p>
@* Enable this once you have account confirmation enabled for password reset functionality
<p>
@Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>*@
</section>
</div>
</div>This is my browser settings (IE11) for cookies:

********** HERE IS WHAT IT LOOKS LIKE WHEN I RUN THE APP **********
Based on what I have set-up, when I run the app, it will take me to the Login Page and I can't get to any of the Home, or Privacy Views until I login. This works. That's not the issue.
I wanted to see what happened if I disabled cookies on the browser. I know I disabled cookies correctly because if I try to log-in to facebook I will get the message "cookies required". Yet, I can run my little test app to my hearts content and it will log me in, expire after 20 seconds (which would force me to log back in once I click a link), etc. No loss of functionality, it works.
- When I first run the app with cookies disabled:

- Then, I log-in using my so@test.com user (type any password):

... And I can navigate to any view I want.
So what am I missing here? Does cookie auth mean something different than the cookies associated with your browser? Or this is some type of server cookie (vs a client cookie or something)? Or does ASP.NET Core figure out a way around that in some way?
********** NEW INFORMATION **********
Looks like I should have tried another browser other than IE. Firefox and Chrome did as expected, whereas IE and Edge ignores the fact that I have its cookies blocked. Does anyone know why? Is this some special magic for Microsoft browsers that other browsers don't have/get?
c# asp.net-core cookies asp.net-core-2.2
I'm finding that I can, so I must be confused about cookies.
********** SETUP SECTION **********
I've done the following:
- Visual Studio 2017: File -> New Project -> ASP.NET Core Web Application -> Web Application (Model-View-Controller). All defaults (so No Authentication, and Configure for HTTPS checked true). Solution Explorer will look like this:

In Startup.cs, I modified ConfigureServices:
public void ConfigureServices(IServiceCollection services)
// THIS WAS COMMENTED OUT
//services.Configure<CookiePolicyOptions>(options =>
//
// // This lambda determines whether user consent for non-essential cookies is needed for a given request.
// options.CheckConsentNeeded = context => true;
// options.MinimumSameSitePolicy = SameSiteMode.None;
//);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// THIS WAS ADDED
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = false;
options.ExpireTimeSpan = TimeSpan.FromSeconds(20);
);In Startup.cs, I modified Configure:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();
// THIS WAS COMMENTED OUT
//app.UseCookiePolicy();
// THIS WAS ADDED
app.UseAuthentication();
app.UseMvc(routes =>
routes.MapRoute(
name: "default",
template: "controller=Home/action=Index/id?");
);In the class for the HomeController.cs that's created for you, I added an [Authorize] tag:
[Authorize]
public class HomeController : Controller
{I added a new class file to the Models folder called AccountModel.cs, this is what it looks like:
namespace WebApplication1.Models
public class LoginViewModel
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email get; set;
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password get; set;
[Display(Name = "Remember me?")]
public bool RememberMe get; set;
I created a New folder called Data and added a new class file called ApplicationUser.cs:
namespace WebApplication1.Data
public class ApplicationUser
public string Email get; set;
public string FullName get; set;
I added a new class file to the Controllers folder called AccountControleler.cs, this is what it looks like:
namespace WebApplication1.Controllers
public class AccountController : Controller
public IActionResult Login()
return View();
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
if (!ModelState.IsValid)
return View(model);
ApplicationUser appUser = await AuthenticateUser(model.Email, model.Password);
if (appUser == null)
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
List<Claim> claims = new List<Claim>
new Claim(ClaimTypes.Name, appUser.FullName),
new Claim("FullName", appUser.FullName),
new Claim(ClaimTypes.Email, appUser.Email),
new Claim(ClaimTypes.Role, "Administrator")
;
ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
AuthenticationProperties authProperties = new AuthenticationProperties();
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
return RedirectToLocal(returnUrl);
private async Task<ApplicationUser> AuthenticateUser(string email, string password)
await Task.Delay(500);
if (email == "so@test.com")
return new ApplicationUser()
Email = "so@test.com",
FullName = "Stack Overflow"
;
else
return null;
private ActionResult RedirectToLocal(string returnUrl)
if (Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
return RedirectToAction("Index", "Home");
I created a New folder under the Views folder called Account and added a new class view called Login.cshtml:
@model WebApplication1.Models.LoginViewModel
@
ViewData["Title"] = "Login";
<h2 class="text-primary">@ViewBag.Title</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@*https://dustinewers.com/how-to-build-html-helpers-like-html-beginform-in-asp-net-mvc/*@
@*https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.rendering.ihtmlhelper.beginform?view=aspnetcore-2.2*@
@*@Html.BeginForm("Login", "Account",TModel-routeValues,FormMethod.Post, bool?-AntiforgeryExtensions, TModel-htmlAttributes)*@
@using (Html.BeginForm("Login", "Account", new ReturnUrl = ViewBag.ReturnUrl , FormMethod.Post, null, new @class = "form-horizontal", role = "form" ))
@Html.AntiForgeryToken()
<h4 class="text-primary">Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true, "", new @class = "text-danger" )
<div class="form-group">
@Html.LabelFor(m => m.Email, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.TextBoxFor(m => m.Email, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Email, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new @class = "col-md-2 control-label" )
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new @class = "form-control" )
@Html.ValidationMessageFor(m => m.Password, "", new @class = "text-danger" )
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default btn-primary" />
</div>
</div>
<p>
@Html.ActionLink("Register as a new user", "Register")
</p>
@* Enable this once you have account confirmation enabled for password reset functionality
<p>
@Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>*@
</section>
</div>
</div>This is my browser settings (IE11) for cookies:

********** HERE IS WHAT IT LOOKS LIKE WHEN I RUN THE APP **********
Based on what I have set-up, when I run the app, it will take me to the Login Page and I can't get to any of the Home, or Privacy Views until I login. This works. That's not the issue.
I wanted to see what happened if I disabled cookies on the browser. I know I disabled cookies correctly because if I try to log-in to facebook I will get the message "cookies required". Yet, I can run my little test app to my hearts content and it will log me in, expire after 20 seconds (which would force me to log back in once I click a link), etc. No loss of functionality, it works.
- When I first run the app with cookies disabled:

- Then, I log-in using my so@test.com user (type any password):

... And I can navigate to any view I want.
So what am I missing here? Does cookie auth mean something different than the cookies associated with your browser? Or this is some type of server cookie (vs a client cookie or something)? Or does ASP.NET Core figure out a way around that in some way?
********** NEW INFORMATION **********
Looks like I should have tried another browser other than IE. Firefox and Chrome did as expected, whereas IE and Edge ignores the fact that I have its cookies blocked. Does anyone know why? Is this some special magic for Microsoft browsers that other browsers don't have/get?
c# asp.net-core cookies asp.net-core-2.2
c# asp.net-core cookies asp.net-core-2.2
edited Mar 27 at 18:04
JustLooking
asked Mar 26 at 22:57
JustLookingJustLooking
1,2092 gold badges14 silver badges30 bronze badges
1,2092 gold badges14 silver badges30 bronze badges
Is there any demo to reproduce your issue? I made a test with your steps, it works correctly when the cookies is disabled and the request will be redirect to the Account controller all the time. Check web browser network tab to see whether there is any cookies in the request and reponse.
– Tao Zhou
Mar 27 at 2:22
Just to clarify, at the very start, mine is always routed to the Account controller until I actually sign-in (my controller does actually perform await HttpContext.SignInAsync - oh, and I do have a Model class, as well). Once I sign-in, I'm able to see any of the Contact, Home, or About pages. All while my browser has cookies disabled
– JustLooking
Mar 27 at 15:57
I really should have tried another browser besides IE11, I suppose. Chrome and Firefox both do what you describe, keep redirecting to the Account controller. Whereas IE11 ignores the fact that my settings are to block all cookies.
– JustLooking
Mar 27 at 17:55
Edge too. So Microsoft browsers work, even when cookies are blocked. But other browsers don't (Firefox and Chrome)
– JustLooking
Mar 27 at 18:03
Fail to reproduce your issue withIE 11 Version 11.55.17763.0
– Tao Zhou
Mar 28 at 5:34
|
show 3 more comments
Is there any demo to reproduce your issue? I made a test with your steps, it works correctly when the cookies is disabled and the request will be redirect to the Account controller all the time. Check web browser network tab to see whether there is any cookies in the request and reponse.
– Tao Zhou
Mar 27 at 2:22
Just to clarify, at the very start, mine is always routed to the Account controller until I actually sign-in (my controller does actually perform await HttpContext.SignInAsync - oh, and I do have a Model class, as well). Once I sign-in, I'm able to see any of the Contact, Home, or About pages. All while my browser has cookies disabled
– JustLooking
Mar 27 at 15:57
I really should have tried another browser besides IE11, I suppose. Chrome and Firefox both do what you describe, keep redirecting to the Account controller. Whereas IE11 ignores the fact that my settings are to block all cookies.
– JustLooking
Mar 27 at 17:55
Edge too. So Microsoft browsers work, even when cookies are blocked. But other browsers don't (Firefox and Chrome)
– JustLooking
Mar 27 at 18:03
Fail to reproduce your issue withIE 11 Version 11.55.17763.0
– Tao Zhou
Mar 28 at 5:34
Is there any demo to reproduce your issue? I made a test with your steps, it works correctly when the cookies is disabled and the request will be redirect to the Account controller all the time. Check web browser network tab to see whether there is any cookies in the request and reponse.
– Tao Zhou
Mar 27 at 2:22
Is there any demo to reproduce your issue? I made a test with your steps, it works correctly when the cookies is disabled and the request will be redirect to the Account controller all the time. Check web browser network tab to see whether there is any cookies in the request and reponse.
– Tao Zhou
Mar 27 at 2:22
Just to clarify, at the very start, mine is always routed to the Account controller until I actually sign-in (my controller does actually perform await HttpContext.SignInAsync - oh, and I do have a Model class, as well). Once I sign-in, I'm able to see any of the Contact, Home, or About pages. All while my browser has cookies disabled
– JustLooking
Mar 27 at 15:57
Just to clarify, at the very start, mine is always routed to the Account controller until I actually sign-in (my controller does actually perform await HttpContext.SignInAsync - oh, and I do have a Model class, as well). Once I sign-in, I'm able to see any of the Contact, Home, or About pages. All while my browser has cookies disabled
– JustLooking
Mar 27 at 15:57
I really should have tried another browser besides IE11, I suppose. Chrome and Firefox both do what you describe, keep redirecting to the Account controller. Whereas IE11 ignores the fact that my settings are to block all cookies.
– JustLooking
Mar 27 at 17:55
I really should have tried another browser besides IE11, I suppose. Chrome and Firefox both do what you describe, keep redirecting to the Account controller. Whereas IE11 ignores the fact that my settings are to block all cookies.
– JustLooking
Mar 27 at 17:55
Edge too. So Microsoft browsers work, even when cookies are blocked. But other browsers don't (Firefox and Chrome)
– JustLooking
Mar 27 at 18:03
Edge too. So Microsoft browsers work, even when cookies are blocked. But other browsers don't (Firefox and Chrome)
– JustLooking
Mar 27 at 18:03
Fail to reproduce your issue with
IE 11 Version 11.55.17763.0– Tao Zhou
Mar 28 at 5:34
Fail to reproduce your issue with
IE 11 Version 11.55.17763.0– Tao Zhou
Mar 28 at 5:34
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367369%2fasp-net-core-2-2-is-it-possible-to-use-cookie-authentication-when-browser-ie1%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367369%2fasp-net-core-2-2-is-it-possible-to-use-cookie-authentication-when-browser-ie1%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is there any demo to reproduce your issue? I made a test with your steps, it works correctly when the cookies is disabled and the request will be redirect to the Account controller all the time. Check web browser network tab to see whether there is any cookies in the request and reponse.
– Tao Zhou
Mar 27 at 2:22
Just to clarify, at the very start, mine is always routed to the Account controller until I actually sign-in (my controller does actually perform await HttpContext.SignInAsync - oh, and I do have a Model class, as well). Once I sign-in, I'm able to see any of the Contact, Home, or About pages. All while my browser has cookies disabled
– JustLooking
Mar 27 at 15:57
I really should have tried another browser besides IE11, I suppose. Chrome and Firefox both do what you describe, keep redirecting to the Account controller. Whereas IE11 ignores the fact that my settings are to block all cookies.
– JustLooking
Mar 27 at 17:55
Edge too. So Microsoft browsers work, even when cookies are blocked. But other browsers don't (Firefox and Chrome)
– JustLooking
Mar 27 at 18:03
Fail to reproduce your issue with
IE 11 Version 11.55.17763.0– Tao Zhou
Mar 28 at 5:34