dir.by  
  Поиск  
Компьютер, программы
.NET Core
 Creating a new application ASP.NET Core 
посмотрели 9757 раз
обновлено: 31 October 2025
Step 1. Open Visual Studio
If you do not have Visual Studio installed you need install Visual Studio...
Open Visual Studio 2022
or
Open Visual Studio 2019
Step 2. Create a blank app ASP.NET Core
Click in the menu: FileNewProjectVisual C#ASP.NET Core Web Application
Here we are offered to choose the type of project:
Empty
a blank template with the least functionality for creating applications from scratch
Web API
Web Service Project
Web Application
the project uses requests to process requests Razor Pages
Web Application (Model-View-Controller)
the project uses architecture MVC
Angular
the project is designed to work with Angular 2+
Reat.js
the project uses React.JS
Reat.js and Redux
the project uses React.JS and Redux
Razor Class Library
a project for creating a class library Razor
We can specify the version ASP.NET Core in the drop-down list. In our case, let's leave the default value ASP.NET Core 2.1.

You can also specify the default authentication type in your project and attach the container Docker.

See also "Configure HTTP". if you select this check box the project will run by protocol by default when debugging and testing HTTPS. In this case, selecting or not selecting this check box is irrelevant. In addition, even if we have set this mark, then later through the project properties we can cancel the launch through HTTPS or, conversely, reinstall.

Among these templates, let's choose Empty. Leave all other values to the default and click on the button OK . And Visual Studio 2017 creates a new project:
Step 3. Project Structure ASP.NET Core
Connected Services
connected services from Azure
Dependencies
packages and libraries added to the project (dependencies)
Properties
To run project settings

  json     {rus}файл{/rus} launchSettings.json
{
     "iisSettings": {
          "windowsAuthentication": false,
          "anonymousAuthentication": true,
          "iisExpress": {
               "applicationUrl": "http://localhost:51459",
               "sslPort": 44390
          }
     },
     "profiles": {
          "IIS Express": {
               "commandName": "IISExpress",
               "launchBrowser": true,
               "environmentVariables": {
                    "ASPNETCORE_ENVIRONMENT": "Development"
               }
          },
          "WebApplication1": {
               "commandName": "Project",
               "launchBrowser": true,
               "applicationUrl": "https://localhost:5001;http://localhost:5000",
               "environmentVariables": {
                    "ASPNETCORE_ENVIRONMENT": "Development"
               }
          }
     }
}
wwwroot
To store files: images, javascript, css, etc., which are used by the application. [konec_stroki] The purpose of this folder is to differentiate access (allow and deny access from the client).
Program.cs
The main application file. This file starts the execution of the program. [konec_stroki] The file code configures and starts the web host within which the application is deployed.
Startup.cs
The file contains a class Startup . The class contains logic for processing incoming requests.
Step 4. Run the ASP.NET Core app
Click on the green triangle at the top
Select the checkmark to agree to create a certificate ssl
In the browser we will see the result
"Hello World!"
Text Hello Word! this is the customer's response (variable Response u class Startup)
  C#     File Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace WebApplication1
{
     public class Startup
     {
          // This method gets called by the runtime. Use this method to add services to the container.
          // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
          public void ConfigureServices(IServiceCollection services)
          {
          }

          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
               if (env.IsDevelopment())
               {
                    app.UseDeveloperExceptionPage();
               }

               app.Run(async (context) =>
               {
                    await context.Response.WriteAsync("Hello World!");
               });
          }
     }
}
Файл Program.cs (оставим без изменений)
  C#     File Program.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

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

          public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
               WebHost.CreateDefaultBuilder(args)
                    .UseStartup<Startup>();
     }
}
 
← Previous topic
What is ASP.NET Core?
 
Next topic →
Creating a new application ASP.NET Core MVC
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

 
What is .NET Core?
Creating a New .NET Core Console App
ASP.NET Core
What is ASP.NET Core?
Creating a new application ASP.NET Core
ASP.NET Core MVC
Creating a new application ASP.NET Core MVC
Built-in IoC container in ASP.NET Core
<BR>
Database (Entity Framework) in ASP.NET Core MVC
Entity Framework in the ASP.NET Core MVC application. Using Code First (we write c# code, and the tables in the database are created by ourselves)
<BR>
Telerik (Kendo UI) in ASP.NET Core MVC
Telerik (Kendo UI) in ASP.NET Core MVC (connect Kendo js files using NPM and Webpack)
<BR>
Authentication (login/register/logout) in the ASP.NET Core MVC application
Authentication is login/register/logout in the ASP.NET Core MVC application
Additional topics, questions
Install a new version (.NET 9) for Visual Studio 2022 | Error: NETSDK1 The current .NET SDK does not support targeting .NET 9.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports .NET 9.0.
Install the new version (.NET 6.0) for Visual Studio 2022. Note! .NET 6.0 is not installed and does not work for Visual Studio 2019
Installing a new version (.NET Core 2.2) for Visual Studio 2019
Choosing between ASP.NET Core and ASP.NET?
Porting code to .NET Core from the .NET Framework
Error "unable to connect to web server "iis express" | ASP.NET Core | Visual Studio 2017
Error "This site can"t be reached" when run ASP.NET Core application | Solution: Recreate the Self-Signed HTTPS Certificate for localhost in IIS Express
WWW sites for learning
Sites to learn ASP.NET Core

  Ваши вопросы присылайте по почте: info@dir.by