How do you disable HTTPS in ASP.NET Core project with Identity?

codeandchips

I have recently created an ASP.NET Core 3.0 web application project in Visual Studio 2019 (with Docker enabled, but I don't think that's relevant), and don't seem to be able to disable HTTPS when including ASP.NET Identity for individual user accounts. Whenever I launch the app in the debugger the page opens using HTTPS and navigating to HTTP redirects me back again.

I've tried creating a new project to test out what is going on, and have found the following:

When creating the project I enabled the use of ASP.NET Identity in order to use local accounts in my app, and I noticed that if I go through the wizard again in order to create a project with the same setup (web app with Identity enabled for individual user accounts) the option to untick the box enabling HTTPS appears to be greyed out.

Unable to disable HTTP on project creation with Identity

After creating the project, I've tried disabling the HTTPS redirection middleware in Startup.cs by commenting out the relevant line:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            //app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }

And have edited the launchSettings.json to try to get the app to run using HTTP instead of HTTPS when debugging, but the app still tries to load using HTTPS.

launchSettings.json BEFORE:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:51767",
      "sslPort": 44396
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "HTTPSTest": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
      "environmentVariables": {
        "ASPNETCORE_URLS": "https://+:443;http://+:80",
        "ASPNETCORE_HTTPS_PORT": "44397"
      },
      "httpPort": 51777,
      "useSSL": true,
      "sslPort": 44397
    }
  }
}

launchSettings.json AFTER:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:51767"
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "HTTPSTest": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
      "environmentVariables": {
      },
      "httpPort": 51777
    }
  }
}

Does anyone have any ideas of what I can try next? I want the app to sit behind an SSL-terminating reverse proxy, so I don't think it's unreasonable to want to disable this.

codeandchips

So I actually managed to fix this. The issue I was seeing with Visual Studio opening up the app using HTTPS was an issue with Visual Studio.

Running through the same setup on another computer worked just fine by commenting out the app.UseHttpsRedirection() line in Startup.cs and removing the SSL references in launchSettings.json as in my original post - running the debugger opened up the page using HTTP and was able to connect to the app.

In order to get everything working again, I tried removing Visual Studio completely, rebooting, reinstalling and trying again, but still had the same issue. In the end I had to also remove all the Visual Studio folders under AppData in my user directory and THEN reinstall Visual Studio, and then it was finally working again when I tried debugging my project!

UPDATE:
This actually came back after the weekend, and I discovered that this time my problem was that HSTS had cached the use of HTTPS in Chrome. Examples of how to remove this for different browsers can be found here: https://appuals.com/how-to-clear-or-disable-hsts-for-chrome-firefox-and-internet-explorer/

In summary, for Chrome:
1. Navigate to chrome://net-internals/#hsts
2. In the Delete domain security policies section, enter localhost as the domain and hit the Delete button

UPDATE 2 - WARNING Although this "fix" allowed me to run my project using HTTP, I did find that Identity would not allow me to log in unless HTTPS was enabled - I think it's something to do with the SignInManager setting an HTTPS-only authentication cookie - see here for further details: AspNet Core Identity - cookie not getting set in production

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do you disable HTTPS in ASP.NET Core project with Identity?

分類Dev

ASP.NET Core on .NET 4.6 - how to do https

分類Dev

Problem running project after Identity scaffolding in ASP.NET Core MVC project on Linux

分類Dev

How to implement permission based authorization in ASP.net core Identity?

分類Dev

How do you encrypt a password within appsettings.json for ASP.net Core 2?

分類Dev

How do you navigate/configure navigation from complex type to entity type in OData in ASP.NET Core?

分類Dev

How do I reference a .NET Framework project in a .NET Core project?

分類Dev

How do I reference a .NET Framework project in a .NET Core project?

分類Dev

How do I reference a .NET Framework project in a .NET Core project?

分類Dev

How do I make project modifications to store Asp .net Core Angurlar 6 bundle in CDN

分類Dev

ASP.NET Core MVC MySQL Identity

分類Dev

Customizing ASP.NET Core Identity Tables

分類Dev

Asp.net core create interface for identity

分類Dev

How to include reference to assembly in ASP.NET Core project

分類Dev

Unable to start ASP.NET Core with HTTPS

分類Dev

ASP.Net Identity Login Redirect Enforce Protocol(Https)

分類Dev

How to remove the role-related tables from ASP.NET Identity Core 2.0

分類Dev

How to decrypt .AspNetCore.Identity.Application cookie in ASP.NET Core 3.0?

分類Dev

How to I access the DbContext of EF core from another project when used in ASP.NET core?

分類Dev

How can we disable ANSI/VT100 color codes added to ASP.NET Core logs

分類Dev

use existing login table with asp.net core identity service

分類Dev

Role based authorization in ASP.NET Core 3.1 with Identity and ExternalLogin

分類Dev

How do you disable semicolons in ESLint for Javascript?

分類Dev

How do I add an Angular project to an exisiting .NET Core Web API project?

分類Dev

How can I read version of project in dotnet core (formerly asp.net mvc6)

分類Dev

How to read Request.Form values in MVC view of asp.net core project?

分類Dev

Use full .NET Framework with existing ASP.NET Core project

分類Dev

ngrok and https tunnel for asp.net core application

分類Dev

Trouble trusting local HTTPs certificate in ASP.NET Core

Related 関連記事

  1. 1

    How do you disable HTTPS in ASP.NET Core project with Identity?

  2. 2

    ASP.NET Core on .NET 4.6 - how to do https

  3. 3

    Problem running project after Identity scaffolding in ASP.NET Core MVC project on Linux

  4. 4

    How to implement permission based authorization in ASP.net core Identity?

  5. 5

    How do you encrypt a password within appsettings.json for ASP.net Core 2?

  6. 6

    How do you navigate/configure navigation from complex type to entity type in OData in ASP.NET Core?

  7. 7

    How do I reference a .NET Framework project in a .NET Core project?

  8. 8

    How do I reference a .NET Framework project in a .NET Core project?

  9. 9

    How do I reference a .NET Framework project in a .NET Core project?

  10. 10

    How do I make project modifications to store Asp .net Core Angurlar 6 bundle in CDN

  11. 11

    ASP.NET Core MVC MySQL Identity

  12. 12

    Customizing ASP.NET Core Identity Tables

  13. 13

    Asp.net core create interface for identity

  14. 14

    How to include reference to assembly in ASP.NET Core project

  15. 15

    Unable to start ASP.NET Core with HTTPS

  16. 16

    ASP.Net Identity Login Redirect Enforce Protocol(Https)

  17. 17

    How to remove the role-related tables from ASP.NET Identity Core 2.0

  18. 18

    How to decrypt .AspNetCore.Identity.Application cookie in ASP.NET Core 3.0?

  19. 19

    How to I access the DbContext of EF core from another project when used in ASP.NET core?

  20. 20

    How can we disable ANSI/VT100 color codes added to ASP.NET Core logs

  21. 21

    use existing login table with asp.net core identity service

  22. 22

    Role based authorization in ASP.NET Core 3.1 with Identity and ExternalLogin

  23. 23

    How do you disable semicolons in ESLint for Javascript?

  24. 24

    How do I add an Angular project to an exisiting .NET Core Web API project?

  25. 25

    How can I read version of project in dotnet core (formerly asp.net mvc6)

  26. 26

    How to read Request.Form values in MVC view of asp.net core project?

  27. 27

    Use full .NET Framework with existing ASP.NET Core project

  28. 28

    ngrok and https tunnel for asp.net core application

  29. 29

    Trouble trusting local HTTPs certificate in ASP.NET Core

ホットタグ

アーカイブ