Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there are 3 different ports for the .net core 2.1 SPA?

I'm learning dotnet core 2.1 SPA, and when I run the donet core 2.1 SPA Angular with dotnet run, I noticed that there are 3 differnt ports:

  1. https:localhost:5001
  2. http:localhost:5000
  3. http:localhost:34941

When I use the second url, it just automatically redirect to the first url, and I got security error. For the 3rd url, it works. I think because it's for the client, where 1st and 2nd url would be used for APIs calls with authentications? What would happen in a live environment?

Result from running <code>dotnet run</code>

The configuration in Program.cs file

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}
like image 450
grepLines Avatar asked Jun 28 '18 02:06

grepLines


People also ask

Should I port my website to NET Core or framework?

"Just porting to .NET Core because it's a new .NET implementation isn't a good enough reason (unless you're a True Fan). ".NET Core is optimized for building highly scalable web applications, running on Windows, macOS or Linux. If you're building Windows desktop applications, then the .NET Framework is the best choice for you.

What's new in ASP NET Core 2?

ASP.NET Core 2.0 recently released and, with it, came some new templates, including new project templates for single-page applications (SPA) served from an ASP.NET Core backend. These templates make it easy to setup a web application with a rich JavaScript frontend and powerful ASP.NET Core backend.

What are the different scenarios for NET Core?

Scenarios for .NET Core Today, four scenarios exist in which you can write code for .NET Core: cross-platform ASP.NET Web apps, cross-platform console apps, cross-platform libraries and frameworks, and UWP apps Built for speed, ASP.NET Core 1.0 is the cross-platform Web stack for .NET Core.

Should I upgrade to net 6+ or port from NET Framework?

Updating from .NET Core 3.1 to .NET 6+ requires much less effort than porting from .NET Framework to .NET Core. For this reason, many customers may choose to upgrade to .NET Core 3.1 first as an incremental step, and then further upgrade to .NET 6 once the upgrade to .NET Core 3.1 has succeeded.


1 Answers

5000 and 5001: Kestrel HTTP and HTTPS Defaults

5000 is for HTTP and 5001 is for HTTPS. Those are defaults in the ASP.NET Core Kestrel Server. 5000 redirects to 5001 because of app.UseHttpsRedirection() in your Startup class.

34941: Any available port for the NG Live Development Server

This is an arbitrary, available port that Microsoft.AspNetCore.SpaServices uses to start the NG Live Development Server. The spa.UseAngularCliServer(npmScript: "start") method in your Startup class calls the the start script from your package.json file like this:

ng serve --extract-css "--port" "50415"`

The port that it passes is any currently available port that the SpaServices find.

See also

  • https://github.com/aspnet/JavaScriptServices
  • https://github.com/aspnet/KestrelHttpServer
like image 71
Shaun Luttin Avatar answered Sep 23 '22 01:09

Shaun Luttin