Ali Hamza
Ali Hamza

Reputation: 21

Google Chrome Browser Block ".AspNetCore.Identity.Application" Cookie In Deployment Only

After deploy asp.net core mvc 6 to iis server the user in case submit a true login not redirected to the controller and not authenticated, when I tracked the cookie in developer tools there is a ! mark on .AspNetCore.Identity.Application and when hover on it there is a message show (This cookie was blocked because it had the "Secure" attribute and the connection was not secure).

What I tried Before

Upvotes: 0

Views: 608

Answers (2)

Ali Hamza
Ali Hamza

Reputation: 21

Because there are many apps host in the server so the browser blocked the cookie cause the other apps have the same cookie name which .AspNetCore.Identity.Application. So simply the issue can be solved by changing the name of the cookie:

builder.Services.AddAuthentication(options => 
{
    options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme;
    options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme;
});

builder.Services.ConfigureApplicationCookie(options => options.Cookie.Name = "AppNameForExample");

Upvotes: 1

Nathan
Nathan

Reputation: 594

Your cookies are configured to require an HTTPS connection. When you try to set them on a non-secure connection, they will be rejected. You can try these steps:

  1. Obtain a valid SSL certificate: You'll need a certificate that is trusted by the browsers you're targeting. Check your web.config file settings for:
<httpCookies requireSSL="true" />
  1. Configure IIS to use HTTPS: This involves binding the SSL certificate to the IIS website and enabling HTTPS.

  2. Update your ASP.NET Core application to use HTTPS: In the Startup.cs file, you can use the following code to redirect all HTTP traffic to HTTPS:

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Rewrite;

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    var options = new RewriteOptions().AddRedirectToHttps();
    app.UseRewriter(options);

    // rest of the code...
}

Upvotes: 0

Related Questions