The CORE profile ASP.NET

ASP.NET Core is a cross-platform, high-performance open source framework for generating new cloud-enabled, internet-connected applications. With ASP.NET Core, you can:

  • Generate Web applications and services, Internet of Things (IoT) applications, and mobile backends.
  • Use your favorite development tools on Windows, macOS, and Linux.
  • Deploy to the cloud or locally.
  • Running on.NET Core.

Why ASP.NET Core?

ASP.NET Core has the following advantages:

  • A unified scenario for generating Web UI and Web API.
  • Build for testability.
  • Razor Pages can make page-based coding simpler and more efficient.
  • Blazor allows you to use C# and JavaScript in your browser. Share server-side and client-side application logic written entirely in.NET.
  • Can be developed and run on Windows, macOS, and Linux.
  • Open source and community-centric.
  • Integrate new client frameworks and development workflows.
  • Support for hosting remote procedure calls (RPC) using gRPC.
  • Environment-based cloud ready configuration system.
  • Built-in dependency injection.
  • Lightweight, high-performance, modular HTTP request pipeline.
  • Can be hosted in the following:
    • Kestrel
    • IIS HTTP.sys
  • Nginx
  • Apache
  • Docker
  • Parallel versioning.
  • Tools to simplify new Web development.

Generate Web apis and Web uis using ASP.NET Core MVC

  • ASP.NET Core MVC provides the functionality required to generate Web apis and Web applications:
  • The Model-View-Controller (MVC) pattern makes Web apis and Web applications testable.
  • Razor Pages is a page-based programming model that makes Web UI generation simpler and more efficient.
  • The Razor tag provides efficient syntax for Razor Pages and MVC views.
  • The tag helper enables server-side code to participate in creating and rendering HTML elements in Razor files.
  • Built-in support for multiple data formats and content negotiation makes the Web API accessible to a variety of clients, including browsers and mobile devices.
  • Model bindings automatically map data in HTTP requests to action method parameters.
  • Model validation automatically performs client-side and server-side validation.

Client development

ASP.NET Core integrates seamlessly with common client frameworks and libraries, including Blazor, Angular, React, and Bootstrap. For more information, see Introduction to ASP.NET Core Blazor and related topics under “Client Development.”

ASP.NET Core target framework

Some of the advantages of.NET Core over the.NET Framework include:

  • Cross-platform. Runs on Windows, macOS, and Linux.
  • Performance is stronger
  • Parallel versioning
  • The new API
  • Open source

ASP.NET CORE MVC

ASP.NET CORE is a development framework for creating web pages and websites using HTML, CSS, JavaScript, and server scripting.

ASP.NET CORE supports three different development modes: Web Pages, MVC, and Web Forms.

MVC programming pattern

MVC is one of the three ASP.NET CORE programming patterns.

MVC is a pattern that uses MVC (Model View Controller) to design and create Web applications:

The Model represents the application core (such as a database record list). View displays data (database records). Controller handles input (writing database records). The MVC pattern provides complete control over HTML, CSS, and JavaScript.

The MVC pattern defines a Web application
With three logical layers:
Business Layer (Model logic)
Display layer (View logic)
Input control (controller logic)

The Model is the part of the application that handles the application’s data logic. Typically, model objects are responsible for accessing data in a database.

The View is the part of the application that handles the display of data. Views are usually created from model data.

The Controller is the part of the application that handles user interaction. Typically the controller is responsible for reading data from the view, controlling user input, and sending data to the model.

MVC layering helps manage complex applications because you can focus on one aspect at a time. For example, you can focus on view design without relying on business logic. It also makes testing your application easier.

MVC layering also simplifies group development. View, controller logic, and business logic can be developed simultaneously by different developers.

Create a Web application

Start VS and select New Project to create a New Project. Select the ASP.NET CORE Web template to create the Project

Define the project name and source location according to the actual requirements of the project

A preview of the completed project is shown below

.net Core application folder

The Properties — launchSettings. Json

The launchSettings.json file stores specific configuration criteria for an ASP.NET Core application, including environment variables, development ports, and so on. Configuration changes made in the launchsettings. json file have the same effect as submitted changes in the project – properties (currently properties are woefully under-right-click) and support synchronous updates.

{
  "iisSettings"Select IIS Express as the boot option"windowsAuthentication": false, # Whether to enable Windows authentication"anonymousAuthentication": true# Whether to enable anonymous authentication"iisExpress": {
      "applicationUrl": "http://localhost:64767"#IIS Express random port"sslPort": 44377}},"profiles": {
    "IIS Express": {
      "commandName": "IISExpress"."launchBrowser": true."environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"}},"webpagetest"{# select local self-host boot, see the program.cs file. Deleting this node will also result in the absence of Visual Studio launch options"commandName": "Project"."launchBrowser": true."applicationUrl": "https://localhost:5001; http://localhost:5000", # localhost port"environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"}}}}Copy the code

Startup.cs

The Startup class is initialized in program. cs.

The startup. cs file is the Startup entry for ASP.NET Core. In addition to constructors, it defines Configure and ConfigureServices methods, which need to be called before Configure.

  • The Configure method is used to handle middleware operations in our program
  • ConfigureServices configures the various services in our application

bundleconfig.json

Bundleconfig. json is a collection of compressed files that can automatically compress associated files for use in projects such as generating

Below and bower. Json

Wwwroot is a folder for static content. It contains files such as CSS, js, img, etc.

appsettings

Again, as the name suggests — application configuration, similar to. NET Framework web. Config file, developers can write system parameters (such as the application connection string) in the appSettings file by key-value pair, and Startup class in the constructor to enable the application to recognize this file

Controllers folder

The Controllers folder contains the control classes responsible for handling user input and responses.

MVC requires that all Controller file names end in “Controller”.

In our example, VS has created the following files: homecontroller.cs (for the Home page and About page) and AccountController.

The Models folder

The Models folder contains the classes that represent the application model.

VS automatically creates an errorViewModel.cs file that contains the model for the application to report errors.

Views folder

The Views folder stores files (HTML files) related to the application display (user interface). Depending on the language content used, these files may be HTML, ASP, ASPX, CSHTML, and VBHTML.

The Views folder contains a folder for each controller.

In the Views folder, VS has created a Home folder and a Shared folder.

The Home folder is used to store application pages such as the Home and About pages.

The Shared folder is used to store views (master pages and layout pages) Shared between controllers.

  • _layout. CSHTML stands for master page
  • Add _ViewImports. CSHTML (Tag Helper) via the Razor Import file template

Tag Helper is one of the most important, but easy to ignore, ways to add tags

@using webpagetest
@using webpagetest.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Copy the code

The invocation code is shown below

 <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">webpagetest</a>
Copy the code

With this knowledge, you have the basics of creating projects for ASP.NET CORE

GitHub address of the blogger

github.com/yuyue5945