0

In my recently developed ASP.Net 7 application, I have the following in y program.cs

 app.UseHttpsRedirection();

And my launchSettings.json is as follows:

{

  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
  "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
    "applicationUrl": "http://localhost:52163",
    "sslPort": 44396
    }
  },
  "profiles": {
  "http": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "http://localhost:5150",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
 },
 "https": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "https://localhost:7253;http://localhost:5150",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
    }
  },
   "IIS Express": {
   "commandName": "IISExpress",
   "launchBrowser": true,
   "launchUrl": "swagger",
   "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
     }
   }
  }
}

I am able to launch the application from Visual Studio but when I publish it and try to run it with powershell with the following command

dotnet projectName.dll

I get the following output indicating that it is running on port 5000

Now listening on: http://localhost:5000

but when I navigate to http://locahost:5000, I get the following on the brwser[![enter image description here][1]][1]

I have also tried to check the application on http://localhost:7253 and on https://locahost:5150 but I keep getting the following:

[![enter image description here][2]][2]

Please how can I resolve this issue

Thank you [1]: https://i.stack.imgur.com/Nq5P4.png [2]: https://i.stack.imgur.com/ajSa4.png

Josh
  • 1,660
  • 5
  • 33
  • 55
  • 1
    Error message indicates the connection is using HTTP instead of HTTPS (secure). It is a warning coming from the browser you are using which is why it is being displayed in PS and not in VS. It is only a warning which you can disable in PS. The client and server have to be consistent. They both need to be using the same port number. The server can be set to use either HTTP or HTTPS (HTTPS required) or both. You cannot sent HTTPS unless the server is configured for HTTPS (including a certificate). – jdweng Apr 14 '23 at 10:17
  • Thank you @jdweng. Please what would you suggest I do right now to ix the issue? – Josh Apr 14 '23 at 11:58
  • There is more than one option and do not know if you prefer working with HTTP or HTTPS. See following : https://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error?force_isolation=true – jdweng Apr 14 '23 at 12:01
  • @Josh when you launch the app in VS it runs in development mode (so the variable for the ASPNETCORE_ENVIRONMENT is set (so the bottom 3 options from launchsettings are ignored when you start the application through Powershell). The top option is only used when you host the app in iis. It looks like your app is now defaulting to use Kestrel which uses port 5000/5001 by default. See https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-7.0 for more information – bluuf Apr 15 '23 at 12:17
  • @Josh see https://stackoverflow.com/questions/60197137/iis-express-vs-dotnet-run for more information and a solution. – bluuf Apr 15 '23 at 12:28

0 Answers0